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)
70 /** Convert GL datatype enum into a <type>_BIT value seen above */
72 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
79 case GL_UNSIGNED_BYTE
:
80 return UNSIGNED_BYTE_BIT
;
83 case GL_UNSIGNED_SHORT
:
84 return UNSIGNED_SHORT_BIT
;
88 return UNSIGNED_INT_BIT
;
90 if (ctx
->Extensions
.ARB_half_float_vertex
)
99 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
100 case GL_UNSIGNED_INT_2_10_10_10_REV
:
101 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
102 case GL_INT_2_10_10_10_REV
:
103 return INT_2_10_10_10_REV_BIT
;
104 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
105 return UNSIGNED_INT_10F_11F_11F_REV_BIT
;
113 * Sets the VertexBinding field in the vertex attribute given by attribIndex.
116 vertex_attrib_binding(struct gl_context
*ctx
, GLuint attribIndex
,
119 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
120 struct gl_vertex_attrib_array
*array
= &vao
->VertexAttrib
[attribIndex
];
122 if (array
->VertexBinding
!= bindingIndex
) {
123 const GLbitfield64 array_bit
= VERT_BIT(attribIndex
);
125 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
127 vao
->VertexBinding
[array
->VertexBinding
]._BoundArrays
&= ~array_bit
;
128 vao
->VertexBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
130 array
->VertexBinding
= bindingIndex
;
132 vao
->NewArrays
|= array_bit
;
138 * Binds a buffer object to the vertex buffer binding point given by index,
139 * and sets the Offset and Stride fields.
142 bind_vertex_buffer(struct gl_context
*ctx
, GLuint index
,
143 struct gl_buffer_object
*vbo
,
144 GLintptr offset
, GLsizei stride
)
146 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
147 struct gl_vertex_buffer_binding
*binding
= &vao
->VertexBinding
[index
];
149 if (binding
->BufferObj
!= vbo
||
150 binding
->Offset
!= offset
||
151 binding
->Stride
!= stride
) {
153 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
155 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
157 binding
->Offset
= offset
;
158 binding
->Stride
= stride
;
160 vao
->NewArrays
|= binding
->_BoundArrays
;
166 * Sets the InstanceDivisor field in the vertex buffer binding point
167 * given by bindingIndex.
170 vertex_binding_divisor(struct gl_context
*ctx
, GLuint bindingIndex
,
173 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
174 struct gl_vertex_buffer_binding
*binding
=
175 &vao
->VertexBinding
[bindingIndex
];
177 if (binding
->InstanceDivisor
!= divisor
) {
178 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
179 binding
->InstanceDivisor
= divisor
;
180 vao
->NewArrays
|= binding
->_BoundArrays
;
186 * Examine the API profile and extensions to determine which types are legal
187 * for vertex arrays. This is called once from update_array_format().
190 get_legal_types_mask(const struct gl_context
*ctx
)
192 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
194 if (_mesa_is_gles(ctx
)) {
195 legalTypesMask
&= ~(FIXED_GL_BIT
|
197 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
199 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
200 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
201 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
202 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
203 * quite as trivial as we'd like because it uses a different enum value
204 * for GL_HALF_FLOAT_OES.
206 if (ctx
->Version
< 30) {
207 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
209 UNSIGNED_INT_2_10_10_10_REV_BIT
|
210 INT_2_10_10_10_REV_BIT
|
215 legalTypesMask
&= ~FIXED_ES_BIT
;
217 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
218 legalTypesMask
&= ~FIXED_GL_BIT
;
220 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
221 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
222 INT_2_10_10_10_REV_BIT
);
224 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
225 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
228 return legalTypesMask
;
233 * Does error checking and updates the format in an attrib array.
235 * Called by update_array() and VertexAttrib*Format().
237 * \param func Name of calling function used for error reporting
238 * \param attrib The index of the attribute array
239 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
240 * \param sizeMin Min allowable size value
241 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
242 * \param size Components per element (1, 2, 3 or 4)
243 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
244 * \param normalized Whether integer types are converted to floats in [-1, 1]
245 * \param integer Integer-valued values (will not be normalized to [-1, 1])
246 * \param relativeOffset Offset of the first element relative to the binding offset.
249 update_array_format(struct gl_context
*ctx
,
251 GLuint attrib
, GLbitfield legalTypesMask
,
252 GLint sizeMin
, GLint sizeMax
,
253 GLint size
, GLenum type
,
254 GLboolean normalized
, GLboolean integer
,
255 GLuint relativeOffset
)
257 struct gl_vertex_attrib_array
*array
;
260 GLenum format
= GL_RGBA
;
262 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
263 /* Compute the LegalTypesMask only once, unless the context API has
264 * changed, in which case we want to compute it again. We can't do this
265 * in _mesa_init_varrays() below because extensions are not yet enabled
268 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
269 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
272 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
274 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
275 /* BGRA ordering is not supported in ES contexts.
280 typeBit
= type_to_bit(ctx
, type
);
281 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
282 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
283 func
, _mesa_lookup_enum_by_nr(type
));
287 /* Do size parameter checking.
288 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
289 * must be handled specially.
291 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
292 sizeMax
== BGRA_OR_4
&&
294 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
296 * "An INVALID_OPERATION error is generated under any of the following
299 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
300 * or UNSIGNED_INT_2_10_10_10_REV;
302 * • size is BGRA and normalized is FALSE;"
304 bool bgra_error
= false;
306 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
307 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
308 type
!= GL_INT_2_10_10_10_REV
&&
309 type
!= GL_UNSIGNED_BYTE
)
311 } else if (type
!= GL_UNSIGNED_BYTE
)
315 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
316 func
, _mesa_lookup_enum_by_nr(type
));
321 _mesa_error(ctx
, GL_INVALID_OPERATION
,
322 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
329 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
330 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
334 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
335 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
336 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
337 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
341 /* The ARB_vertex_attrib_binding_spec says:
343 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
344 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
346 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
347 _mesa_error(ctx
, GL_INVALID_VALUE
,
348 "%s(relativeOffset=%d > "
349 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
350 func
, relativeOffset
);
354 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
355 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
356 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
362 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
363 assert(elementSize
!= -1);
365 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
368 array
->Format
= format
;
369 array
->Normalized
= normalized
;
370 array
->Integer
= integer
;
371 array
->RelativeOffset
= relativeOffset
;
372 array
->_ElementSize
= elementSize
;
374 ctx
->Array
.VAO
->NewArrays
|= VERT_BIT(attrib
);
375 ctx
->NewState
|= _NEW_ARRAY
;
382 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
385 * \param func name of calling function used for error reporting
386 * \param attrib the attribute array index to update
387 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
388 * \param sizeMin min allowable size value
389 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
390 * \param size components per element (1, 2, 3 or 4)
391 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
392 * \param stride stride between elements, in elements
393 * \param normalized are integer types converted to floats in [-1, 1]?
394 * \param integer integer-valued values (will not be normalized to [-1,1])
395 * \param ptr the address (or offset inside VBO) of the array data
398 update_array(struct gl_context
*ctx
,
400 GLuint attrib
, GLbitfield legalTypesMask
,
401 GLint sizeMin
, GLint sizeMax
,
402 GLint size
, GLenum type
, GLsizei stride
,
403 GLboolean normalized
, GLboolean integer
,
406 struct gl_vertex_attrib_array
*array
;
407 GLsizei effectiveStride
;
409 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
411 * "Client vertex arrays - all vertex array attribute pointers must
412 * refer to buffer objects (section 2.9.2). The default vertex array
413 * object (the name zero) is also deprecated. Calling
414 * VertexAttribPointer when no buffer object or no vertex array object
415 * is bound will generate an INVALID_OPERATION error..."
417 * The check for VBOs is handled below.
419 if (ctx
->API
== API_OPENGL_CORE
420 && (ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
)) {
421 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
427 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
431 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
432 stride
> ctx
->Const
.MaxVertexAttribStride
) {
433 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
434 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
438 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
440 * "An INVALID_OPERATION error is generated under any of the following
445 * * any of the *Pointer commands specifying the location and
446 * organization of vertex array data are called while zero is bound
447 * to the ARRAY_BUFFER buffer object binding point (see section
448 * 2.9.6), and the pointer argument is not NULL."
450 if (ptr
!= NULL
&& ctx
->Array
.VAO
->ARBsemantics
&&
451 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
452 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
456 if (!update_array_format(ctx
, func
, attrib
, legalTypesMask
, sizeMin
,
457 sizeMax
, size
, type
, normalized
, integer
, 0)) {
461 /* Reset the vertex attrib binding */
462 vertex_attrib_binding(ctx
, attrib
, attrib
);
464 /* The Stride and Ptr fields are not set by update_array_format() */
465 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
466 array
->Stride
= stride
;
467 array
->Ptr
= (const GLvoid
*) ptr
;
469 /* Update the vertex buffer binding */
470 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
471 bind_vertex_buffer(ctx
, attrib
, ctx
->Array
.ArrayBufferObj
,
472 (GLintptr
) ptr
, effectiveStride
);
477 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
479 GET_CURRENT_CONTEXT(ctx
);
480 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
481 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
482 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
483 DOUBLE_BIT
| HALF_BIT
|
484 UNSIGNED_INT_2_10_10_10_REV_BIT
|
485 INT_2_10_10_10_REV_BIT
);
487 FLUSH_VERTICES(ctx
, 0);
489 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
491 size
, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
496 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
498 GET_CURRENT_CONTEXT(ctx
);
499 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
500 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
501 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
502 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
503 UNSIGNED_INT_2_10_10_10_REV_BIT
|
504 INT_2_10_10_10_REV_BIT
);
506 FLUSH_VERTICES(ctx
, 0);
508 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
510 3, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
515 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
517 GET_CURRENT_CONTEXT(ctx
);
518 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
519 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
520 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
521 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
522 INT_BIT
| UNSIGNED_INT_BIT
|
523 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
524 UNSIGNED_INT_2_10_10_10_REV_BIT
|
525 INT_2_10_10_10_REV_BIT
);
526 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
528 FLUSH_VERTICES(ctx
, 0);
530 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
531 legalTypes
, sizeMin
, BGRA_OR_4
,
532 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
537 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
539 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
540 GET_CURRENT_CONTEXT(ctx
);
542 FLUSH_VERTICES(ctx
, 0);
544 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
546 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
551 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
553 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
554 FLOAT_BIT
| DOUBLE_BIT
);
555 GET_CURRENT_CONTEXT(ctx
);
557 FLUSH_VERTICES(ctx
, 0);
559 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
561 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
566 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
567 GLsizei stride
, const GLvoid
*ptr
)
569 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
570 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
571 INT_BIT
| UNSIGNED_INT_BIT
|
572 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
573 UNSIGNED_INT_2_10_10_10_REV_BIT
|
574 INT_2_10_10_10_REV_BIT
);
575 GET_CURRENT_CONTEXT(ctx
);
577 FLUSH_VERTICES(ctx
, 0);
579 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
580 legalTypes
, 3, BGRA_OR_4
,
581 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
586 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
589 GET_CURRENT_CONTEXT(ctx
);
590 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
591 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
592 : (SHORT_BIT
| INT_BIT
|
593 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
594 UNSIGNED_INT_2_10_10_10_REV_BIT
|
595 INT_2_10_10_10_REV_BIT
);
596 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
597 const GLuint unit
= ctx
->Array
.ActiveTexture
;
599 FLUSH_VERTICES(ctx
, 0);
601 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
602 legalTypes
, sizeMin
, 4,
603 size
, type
, stride
, GL_FALSE
, GL_FALSE
,
609 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
611 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
612 /* this is the same type that glEdgeFlag uses */
613 const GLboolean integer
= GL_FALSE
;
614 GET_CURRENT_CONTEXT(ctx
);
616 FLUSH_VERTICES(ctx
, 0);
618 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
620 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, ptr
);
625 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
627 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
628 GET_CURRENT_CONTEXT(ctx
);
630 FLUSH_VERTICES(ctx
, 0);
632 if (ctx
->API
!= API_OPENGLES
) {
633 _mesa_error(ctx
, GL_INVALID_OPERATION
,
634 "glPointSizePointer(ES 1.x only)");
638 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
640 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
645 * Set a generic vertex attribute array.
646 * Note that these arrays DO NOT alias the conventional GL vertex arrays
647 * (position, normal, color, fog, texcoord, etc).
650 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
651 GLboolean normalized
,
652 GLsizei stride
, const GLvoid
*ptr
)
654 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
655 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
656 INT_BIT
| UNSIGNED_INT_BIT
|
657 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
658 FIXED_ES_BIT
| FIXED_GL_BIT
|
659 UNSIGNED_INT_2_10_10_10_REV_BIT
|
660 INT_2_10_10_10_REV_BIT
|
661 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
662 GET_CURRENT_CONTEXT(ctx
);
664 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
665 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
669 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
670 legalTypes
, 1, BGRA_OR_4
,
671 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
676 * GL_EXT_gpu_shader4 / GL 3.0.
677 * Set an integer-valued vertex attribute array.
678 * Note that these arrays DO NOT alias the conventional GL vertex arrays
679 * (position, normal, color, fog, texcoord, etc).
682 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
683 GLsizei stride
, const GLvoid
*ptr
)
685 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
686 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
687 INT_BIT
| UNSIGNED_INT_BIT
);
688 const GLboolean normalized
= GL_FALSE
;
689 const GLboolean integer
= GL_TRUE
;
690 GET_CURRENT_CONTEXT(ctx
);
692 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
693 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
697 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
699 size
, type
, stride
, normalized
, integer
, ptr
);
705 _mesa_EnableVertexAttribArray(GLuint index
)
707 struct gl_vertex_array_object
*vao
;
708 GET_CURRENT_CONTEXT(ctx
);
710 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
711 _mesa_error(ctx
, GL_INVALID_VALUE
,
712 "glEnableVertexAttribArrayARB(index)");
716 vao
= ctx
->Array
.VAO
;
718 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
720 if (!vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
721 /* was disabled, now being enabled */
722 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
723 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
724 vao
->_Enabled
|= VERT_BIT_GENERIC(index
);
725 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
731 _mesa_DisableVertexAttribArray(GLuint index
)
733 struct gl_vertex_array_object
*vao
;
734 GET_CURRENT_CONTEXT(ctx
);
736 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
737 _mesa_error(ctx
, GL_INVALID_VALUE
,
738 "glDisableVertexAttribArrayARB(index)");
742 vao
= ctx
->Array
.VAO
;
744 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
746 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
747 /* was enabled, now being disabled */
748 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
749 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
750 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
751 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
757 * Return info for a vertex attribute array (no alias with legacy
758 * vertex attributes (pos, normal, color, etc)). This function does
759 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
762 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
765 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
766 const struct gl_vertex_attrib_array
*array
;
768 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
769 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
773 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
775 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
778 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
779 return array
->Enabled
;
780 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
781 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
782 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
783 return array
->Stride
;
784 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
786 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
787 return array
->Normalized
;
788 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
789 return vao
->VertexBinding
[array
->VertexBinding
].BufferObj
->Name
;
790 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
791 if ((_mesa_is_desktop_gl(ctx
)
792 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
793 || _mesa_is_gles3(ctx
)) {
794 return array
->Integer
;
797 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
798 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
799 || _mesa_is_gles3(ctx
)) {
800 return vao
->VertexBinding
[array
->VertexBinding
].InstanceDivisor
;
803 case GL_VERTEX_ATTRIB_BINDING
:
804 if (_mesa_is_desktop_gl(ctx
)) {
805 return array
->VertexBinding
- VERT_ATTRIB_GENERIC0
;
808 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
809 if (_mesa_is_desktop_gl(ctx
)) {
810 return array
->RelativeOffset
;
818 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
823 static const GLfloat
*
824 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
827 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
828 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
832 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
833 _mesa_error(ctx
, GL_INVALID_VALUE
,
834 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
838 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
840 FLUSH_CURRENT(ctx
, 0);
841 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
845 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
847 GET_CURRENT_CONTEXT(ctx
);
849 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
850 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
856 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
857 "glGetVertexAttribfv");
863 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
865 GET_CURRENT_CONTEXT(ctx
);
867 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
868 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
870 params
[0] = (GLdouble
) v
[0];
871 params
[1] = (GLdouble
) v
[1];
872 params
[2] = (GLdouble
) v
[2];
873 params
[3] = (GLdouble
) v
[3];
877 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
878 "glGetVertexAttribdv");
884 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
886 GET_CURRENT_CONTEXT(ctx
);
888 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
889 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
891 /* XXX should floats in[0,1] be scaled to full int range? */
892 params
[0] = (GLint
) v
[0];
893 params
[1] = (GLint
) v
[1];
894 params
[2] = (GLint
) v
[2];
895 params
[3] = (GLint
) v
[3];
899 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
900 "glGetVertexAttribiv");
907 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
909 GET_CURRENT_CONTEXT(ctx
);
911 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
912 const GLint
*v
= (const GLint
*)
913 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
919 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
920 "glGetVertexAttribIiv");
927 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
929 GET_CURRENT_CONTEXT(ctx
);
931 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
932 const GLuint
*v
= (const GLuint
*)
933 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
939 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
940 "glGetVertexAttribIuiv");
946 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
948 GET_CURRENT_CONTEXT(ctx
);
950 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
951 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
955 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
956 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
960 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
962 *pointer
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
967 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
968 GLsizei count
, const GLvoid
*ptr
)
971 _mesa_VertexPointer(size
, type
, stride
, ptr
);
976 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
980 _mesa_NormalPointer(type
, stride
, ptr
);
985 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
989 _mesa_ColorPointer(size
, type
, stride
, ptr
);
994 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
998 _mesa_IndexPointer(type
, stride
, ptr
);
1003 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1004 GLsizei count
, const GLvoid
*ptr
)
1007 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1012 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1015 _mesa_EdgeFlagPointer(stride
, ptr
);
1020 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1022 GET_CURRENT_CONTEXT(ctx
);
1023 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1024 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1025 GLenum ctype
= 0; /* color type */
1026 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1027 const GLint toffset
= 0; /* always zero */
1028 GLint defstride
; /* default stride */
1031 FLUSH_VERTICES(ctx
, 0);
1033 f
= sizeof(GLfloat
);
1034 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1037 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1043 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1044 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1049 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1050 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1055 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1056 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1057 ctype
= GL_UNSIGNED_BYTE
;
1060 defstride
= c
+ 2*f
;
1063 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1064 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1065 ctype
= GL_UNSIGNED_BYTE
;
1068 defstride
= c
+ 3*f
;
1071 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1072 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1079 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1080 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1085 case GL_C4F_N3F_V3F
:
1086 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1087 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1095 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1096 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1101 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1102 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1106 case GL_T2F_C4UB_V3F
:
1107 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1108 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1109 ctype
= GL_UNSIGNED_BYTE
;
1114 case GL_T2F_C3F_V3F
:
1115 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1116 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1122 case GL_T2F_N3F_V3F
:
1123 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1124 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1129 case GL_T2F_C4F_N3F_V3F
:
1130 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1131 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1138 case GL_T4F_C4F_N3F_V4F
:
1139 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1140 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1148 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1156 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1157 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1158 /* XXX also disable secondary color and generic arrays? */
1162 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1163 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1164 (GLubyte
*) pointer
+ toffset
);
1167 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1172 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1173 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1174 (GLubyte
*) pointer
+ coffset
);
1177 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1183 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1184 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1187 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1191 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1192 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1193 (GLubyte
*) pointer
+ voffset
);
1198 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1200 GET_CURRENT_CONTEXT(ctx
);
1202 FLUSH_VERTICES(ctx
, 0);
1204 if (MESA_VERBOSE
& VERBOSE_API
)
1205 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1208 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1212 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1215 if (ctx
->Array
.LockCount
!= 0) {
1216 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1220 ctx
->Array
.LockFirst
= first
;
1221 ctx
->Array
.LockCount
= count
;
1223 ctx
->NewState
|= _NEW_ARRAY
;
1228 _mesa_UnlockArraysEXT( void )
1230 GET_CURRENT_CONTEXT(ctx
);
1232 FLUSH_VERTICES(ctx
, 0);
1234 if (MESA_VERBOSE
& VERBOSE_API
)
1235 _mesa_debug(ctx
, "glUnlockArrays\n");
1237 if (ctx
->Array
.LockCount
== 0) {
1238 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1242 ctx
->Array
.LockFirst
= 0;
1243 ctx
->Array
.LockCount
= 0;
1244 ctx
->NewState
|= _NEW_ARRAY
;
1248 /* GL_EXT_multi_draw_arrays */
1250 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1251 const GLsizei
*count
, GLsizei primcount
)
1253 GET_CURRENT_CONTEXT(ctx
);
1256 FLUSH_VERTICES(ctx
, 0);
1258 for (i
= 0; i
< primcount
; i
++) {
1260 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1266 /* GL_IBM_multimode_draw_arrays */
1268 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1269 const GLsizei
* count
,
1270 GLsizei primcount
, GLint modestride
)
1272 GET_CURRENT_CONTEXT(ctx
);
1275 FLUSH_VERTICES(ctx
, 0);
1277 for ( i
= 0 ; i
< primcount
; i
++ ) {
1278 if ( count
[i
] > 0 ) {
1279 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1280 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1286 /* GL_IBM_multimode_draw_arrays */
1288 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1289 GLenum type
, const GLvoid
* const * indices
,
1290 GLsizei primcount
, GLint modestride
)
1292 GET_CURRENT_CONTEXT(ctx
);
1295 FLUSH_VERTICES(ctx
, 0);
1297 /* XXX not sure about ARB_vertex_buffer_object handling here */
1299 for ( i
= 0 ; i
< primcount
; i
++ ) {
1300 if ( count
[i
] > 0 ) {
1301 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1302 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1310 * GL_NV_primitive_restart and GL 3.1
1313 _mesa_PrimitiveRestartIndex(GLuint index
)
1315 GET_CURRENT_CONTEXT(ctx
);
1317 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1318 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1322 if (ctx
->Array
.RestartIndex
!= index
) {
1323 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1324 ctx
->Array
.RestartIndex
= index
;
1330 * See GL_ARB_instanced_arrays.
1331 * Note that the instance divisor only applies to generic arrays, not
1332 * the legacy vertex arrays.
1335 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1337 GET_CURRENT_CONTEXT(ctx
);
1339 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1341 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1342 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1346 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1347 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1352 assert(genericIndex
< ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1354 /* The ARB_vertex_attrib_binding spec says:
1358 * void VertexAttribDivisor(uint index, uint divisor);
1360 * is equivalent to (assuming no errors are generated):
1362 * VertexAttribBinding(index, index);
1363 * VertexBindingDivisor(index, divisor);"
1365 vertex_attrib_binding(ctx
, genericIndex
, genericIndex
);
1366 vertex_binding_divisor(ctx
, genericIndex
, divisor
);
1371 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1373 /* From the OpenGL 4.3 core specification, page 302:
1374 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1375 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1378 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1380 case GL_UNSIGNED_BYTE
:
1382 case GL_UNSIGNED_SHORT
:
1384 case GL_UNSIGNED_INT
:
1387 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1391 return ctx
->Array
.RestartIndex
;
1396 * GL_ARB_vertex_attrib_binding
1399 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1402 GET_CURRENT_CONTEXT(ctx
);
1403 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1404 struct gl_buffer_object
*vbo
;
1406 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1408 /* The ARB_vertex_attrib_binding spec says:
1410 * "An INVALID_OPERATION error is generated if no vertex array object
1413 if (ctx
->API
== API_OPENGL_CORE
&&
1414 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1415 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1416 "glBindVertexBuffer(No array object bound)");
1420 /* The ARB_vertex_attrib_binding spec says:
1422 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1423 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1425 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1426 _mesa_error(ctx
, GL_INVALID_VALUE
,
1427 "glBindVertexBuffer(bindingindex=%u > "
1428 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1433 /* The ARB_vertex_attrib_binding spec says:
1435 * "The error INVALID_VALUE is generated if <stride> or <offset>
1439 _mesa_error(ctx
, GL_INVALID_VALUE
,
1440 "glBindVertexBuffer(offset=%" PRId64
" < 0)",
1446 _mesa_error(ctx
, GL_INVALID_VALUE
,
1447 "glBindVertexBuffer(stride=%d < 0)", stride
);
1451 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1452 stride
> ctx
->Const
.MaxVertexAttribStride
) {
1453 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindVertexBuffer(stride=%d > "
1454 "GL_MAX_VERTEX_ATTRIB_STRIDE)", stride
);
1458 if (buffer
== vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1459 vbo
= vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1460 } else if (buffer
!= 0) {
1461 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1463 /* From the GL_ARB_vertex_attrib_array spec:
1465 * "[Core profile only:]
1466 * An INVALID_OPERATION error is generated if buffer is not zero or a
1467 * name returned from a previous call to GenBuffers, or if such a name
1468 * has since been deleted with DeleteBuffers.
1470 * Otherwise, we fall back to the same compat profile behavior as other
1471 * object references (automatically gen it).
1473 if (!_mesa_handle_bind_buffer_gen(ctx
, GL_ARRAY_BUFFER
, buffer
,
1474 &vbo
, "glBindVertexBuffer"))
1477 /* The ARB_vertex_attrib_binding spec says:
1479 * "If <buffer> is zero, any buffer object attached to this
1480 * bindpoint is detached."
1482 vbo
= ctx
->Shared
->NullBufferObj
;
1485 bind_vertex_buffer(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
),
1486 vbo
, offset
, stride
);
1491 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1492 const GLintptr
*offsets
, const GLsizei
*strides
)
1494 GET_CURRENT_CONTEXT(ctx
);
1495 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1498 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1500 /* The ARB_vertex_attrib_binding spec says:
1502 * "An INVALID_OPERATION error is generated if no
1503 * vertex array object is bound."
1505 if (ctx
->API
== API_OPENGL_CORE
&&
1506 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1507 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1508 "glBindVertexBuffers(No array object bound)");
1512 /* The ARB_multi_bind spec says:
1514 * "An INVALID_OPERATION error is generated if <first> + <count>
1515 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1517 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1518 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1519 "glBindVertexBuffers(first=%u + count=%d > the value of "
1520 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1521 first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1527 * The ARB_multi_bind spec says:
1529 * "If <buffers> is NULL, each affected vertex buffer binding point
1530 * from <first> through <first>+<count>-1 will be reset to have no
1531 * bound buffer object. In this case, the offsets and strides
1532 * associated with the binding points are set to default values,
1533 * ignoring <offsets> and <strides>."
1535 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1537 for (i
= 0; i
< count
; i
++)
1538 bind_vertex_buffer(ctx
, VERT_ATTRIB_GENERIC(first
+ i
), vbo
, 0, 16);
1543 /* Note that the error semantics for multi-bind commands differ from
1544 * those of other GL commands.
1546 * The Issues section in the ARB_multi_bind spec says:
1548 * "(11) Typically, OpenGL specifies that if an error is generated by
1549 * a command, that command has no effect. This is somewhat
1550 * unfortunate for multi-bind commands, because it would require
1551 * a first pass to scan the entire list of bound objects for
1552 * errors and then a second pass to actually perform the
1553 * bindings. Should we have different error semantics?
1555 * RESOLVED: Yes. In this specification, when the parameters for
1556 * one of the <count> binding points are invalid, that binding
1557 * point is not updated and an error will be generated. However,
1558 * other binding points in the same command will be updated if
1559 * their parameters are valid and no other error occurs."
1562 _mesa_begin_bufferobj_lookups(ctx
);
1564 for (i
= 0; i
< count
; i
++) {
1565 struct gl_buffer_object
*vbo
;
1567 /* The ARB_multi_bind spec says:
1569 * "An INVALID_VALUE error is generated if any value in
1570 * <offsets> or <strides> is negative (per binding)."
1572 if (offsets
[i
] < 0) {
1573 _mesa_error(ctx
, GL_INVALID_VALUE
,
1574 "glBindVertexBuffers(offsets[%u]=%" PRId64
" < 0)",
1575 i
, (int64_t) offsets
[i
]);
1579 if (strides
[i
] < 0) {
1580 _mesa_error(ctx
, GL_INVALID_VALUE
,
1581 "glBindVertexBuffers(strides[%u]=%d < 0)",
1586 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1587 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
1588 _mesa_error(ctx
, GL_INVALID_VALUE
,
1589 "glBindVertexBuffers(strides[%u]=%d > "
1590 "GL_MAX_VERTEX_ATTRIB_STRIDE)", i
, strides
[i
]);
1595 struct gl_vertex_buffer_binding
*binding
=
1596 &vao
->VertexBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1598 if (buffers
[i
] == binding
->BufferObj
->Name
)
1599 vbo
= binding
->BufferObj
;
1601 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
1602 "glBindVertexBuffers");
1607 vbo
= ctx
->Shared
->NullBufferObj
;
1610 bind_vertex_buffer(ctx
, VERT_ATTRIB_GENERIC(first
+ i
), vbo
,
1611 offsets
[i
], strides
[i
]);
1614 _mesa_end_bufferobj_lookups(ctx
);
1619 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1620 GLboolean normalized
, GLuint relativeOffset
)
1622 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1623 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1624 INT_BIT
| UNSIGNED_INT_BIT
|
1625 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1627 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1628 INT_2_10_10_10_REV_BIT
|
1629 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1631 GET_CURRENT_CONTEXT(ctx
);
1632 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1634 /* The ARB_vertex_attrib_binding spec says:
1636 * "An INVALID_OPERATION error is generated under any of the following
1638 * - if no vertex array object is currently bound (see section 2.10);
1641 if (ctx
->API
== API_OPENGL_CORE
&&
1642 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1643 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1644 "glVertexAttribFormat(No array object bound)");
1648 /* The ARB_vertex_attrib_binding spec says:
1650 * "The error INVALID_VALUE is generated if index is greater than or equal
1651 * to the value of MAX_VERTEX_ATTRIBS."
1653 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1654 _mesa_error(ctx
, GL_INVALID_VALUE
,
1655 "glVertexAttribFormat(attribindex=%u > "
1656 "GL_MAX_VERTEX_ATTRIBS)",
1661 FLUSH_VERTICES(ctx
, 0);
1663 update_array_format(ctx
, "glVertexAttribFormat",
1664 VERT_ATTRIB_GENERIC(attribIndex
),
1665 legalTypes
, 1, BGRA_OR_4
, size
, type
, normalized
,
1666 GL_FALSE
, relativeOffset
);
1671 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1672 GLuint relativeOffset
)
1674 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1675 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1676 INT_BIT
| UNSIGNED_INT_BIT
);
1678 GET_CURRENT_CONTEXT(ctx
);
1679 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1681 /* The ARB_vertex_attrib_binding spec says:
1683 * "An INVALID_OPERATION error is generated under any of the following
1685 * - if no vertex array object is currently bound (see section 2.10);
1688 if (ctx
->API
== API_OPENGL_CORE
&&
1689 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1690 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1691 "glVertexAttribIFormat(No array object bound)");
1695 /* The ARB_vertex_attrib_binding spec says:
1697 * "The error INVALID_VALUE is generated if index is greater than
1698 * or equal to the value of MAX_VERTEX_ATTRIBS."
1700 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1701 _mesa_error(ctx
, GL_INVALID_VALUE
,
1702 "glVertexAttribIFormat(attribindex=%u > "
1703 "GL_MAX_VERTEX_ATTRIBS)",
1708 FLUSH_VERTICES(ctx
, 0);
1710 update_array_format(ctx
, "glVertexAttribIFormat",
1711 VERT_ATTRIB_GENERIC(attribIndex
),
1712 legalTypes
, 1, 4, size
, type
, GL_FALSE
, GL_TRUE
,
1718 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1719 GLuint relativeOffset
)
1721 const GLbitfield legalTypes
= DOUBLE_BIT
;
1723 GET_CURRENT_CONTEXT(ctx
);
1724 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1726 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
1728 * "An INVALID_OPERATION error is generated under any of the following
1730 * • if no vertex array object is currently bound (see section 10.4);
1733 * This language is missing from the extension spec, but we assume
1734 * that this is an oversight.
1736 if (ctx
->API
== API_OPENGL_CORE
&&
1737 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1738 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1739 "glVertexAttribLFormat(No array object bound)");
1743 /* The ARB_vertex_attrib_binding spec says:
1745 * "The error INVALID_VALUE is generated if <attribindex> is greater than
1746 * or equal to the value of MAX_VERTEX_ATTRIBS."
1748 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1749 _mesa_error(ctx
, GL_INVALID_VALUE
,
1750 "glVertexAttribLFormat(attribindex=%u > "
1751 "GL_MAX_VERTEX_ATTRIBS)",
1756 FLUSH_VERTICES(ctx
, 0);
1758 update_array_format(ctx
, "glVertexAttribLFormat",
1759 VERT_ATTRIB_GENERIC(attribIndex
),
1760 legalTypes
, 1, 4, size
, type
, GL_FALSE
, GL_FALSE
,
1766 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
1768 GET_CURRENT_CONTEXT(ctx
);
1769 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1771 /* The ARB_vertex_attrib_binding spec says:
1773 * "An INVALID_OPERATION error is generated if no vertex array object
1776 if (ctx
->API
== API_OPENGL_CORE
&&
1777 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1778 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1779 "glVertexAttribBinding(No array object bound)");
1783 /* The ARB_vertex_attrib_binding spec says:
1785 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1786 * <bindingindex> must be less than the value of
1787 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1790 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1791 _mesa_error(ctx
, GL_INVALID_VALUE
,
1792 "glVertexAttribBinding(attribindex=%u >= "
1793 "GL_MAX_VERTEX_ATTRIBS)",
1798 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1799 _mesa_error(ctx
, GL_INVALID_VALUE
,
1800 "glVertexAttribBinding(bindingindex=%u >= "
1801 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1806 assert(VERT_ATTRIB_GENERIC(attribIndex
) <
1807 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1809 vertex_attrib_binding(ctx
, VERT_ATTRIB_GENERIC(attribIndex
),
1810 VERT_ATTRIB_GENERIC(bindingIndex
));
1815 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
1817 GET_CURRENT_CONTEXT(ctx
);
1818 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1820 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1821 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexBindingDivisor()");
1825 /* The ARB_vertex_attrib_binding spec says:
1827 * "An INVALID_OPERATION error is generated if no vertex array object
1830 if (ctx
->API
== API_OPENGL_CORE
&&
1831 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1832 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1833 "glVertexBindingDivisor(No array object bound)");
1837 /* The ARB_vertex_attrib_binding spec says:
1839 * "An INVALID_VALUE error is generated if <bindingindex> is greater
1840 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
1842 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1843 _mesa_error(ctx
, GL_INVALID_VALUE
,
1844 "glVertexBindingDivisor(bindingindex=%u > "
1845 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1850 vertex_binding_divisor(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
1855 * Copy one client vertex array to another.
1858 _mesa_copy_client_array(struct gl_context
*ctx
,
1859 struct gl_client_array
*dst
,
1860 struct gl_client_array
*src
)
1862 dst
->Size
= src
->Size
;
1863 dst
->Type
= src
->Type
;
1864 dst
->Format
= src
->Format
;
1865 dst
->Stride
= src
->Stride
;
1866 dst
->StrideB
= src
->StrideB
;
1867 dst
->Ptr
= src
->Ptr
;
1868 dst
->Enabled
= src
->Enabled
;
1869 dst
->Normalized
= src
->Normalized
;
1870 dst
->Integer
= src
->Integer
;
1871 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1872 dst
->_ElementSize
= src
->_ElementSize
;
1873 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1877 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
1878 struct gl_vertex_attrib_array
*dst
,
1879 const struct gl_vertex_attrib_array
*src
)
1881 dst
->Size
= src
->Size
;
1882 dst
->Type
= src
->Type
;
1883 dst
->Format
= src
->Format
;
1884 dst
->VertexBinding
= src
->VertexBinding
;
1885 dst
->RelativeOffset
= src
->RelativeOffset
;
1886 dst
->Format
= src
->Format
;
1887 dst
->Integer
= src
->Integer
;
1888 dst
->Normalized
= src
->Normalized
;
1889 dst
->Ptr
= src
->Ptr
;
1890 dst
->Enabled
= src
->Enabled
;
1891 dst
->_ElementSize
= src
->_ElementSize
;
1895 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
1896 struct gl_vertex_buffer_binding
*dst
,
1897 const struct gl_vertex_buffer_binding
*src
)
1899 dst
->Offset
= src
->Offset
;
1900 dst
->Stride
= src
->Stride
;
1901 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1902 dst
->_BoundArrays
= src
->_BoundArrays
;
1904 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1908 * Print vertex array's fields.
1911 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1914 fprintf(stderr
, " %s[%d]: ", name
, index
);
1916 fprintf(stderr
, " %s: ", name
);
1917 fprintf(stderr
, "Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
1918 array
->Ptr
, array
->Type
, array
->Size
,
1919 array
->_ElementSize
, array
->StrideB
,
1920 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
);
1925 * Print current vertex object/array info. For debug.
1928 _mesa_print_arrays(struct gl_context
*ctx
)
1930 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1933 printf("Array Object %u\n", vao
->Name
);
1934 if (vao
->_VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
1935 print_array("Vertex", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_POS
]);
1936 if (vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
1937 print_array("Normal", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
]);
1938 if (vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
1939 print_array("Color", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
]);
1940 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
1941 if (vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
1942 print_array("TexCoord", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
1943 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
1944 if (vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
1945 print_array("Attrib", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
1950 * Initialize vertex array state for given context.
1953 _mesa_init_varray(struct gl_context
*ctx
)
1955 ctx
->Array
.DefaultVAO
= ctx
->Driver
.NewArrayObject(ctx
, 0);
1956 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
1957 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1959 ctx
->Array
.Objects
= _mesa_NewHashTable();
1964 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1967 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1969 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
1970 struct gl_context
*ctx
= (struct gl_context
*) userData
;
1971 _mesa_delete_vao(ctx
, vao
);
1976 * Free vertex array state for given context.
1979 _mesa_free_varray_data(struct gl_context
*ctx
)
1981 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1982 _mesa_DeleteHashTable(ctx
->Array
.Objects
);