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 if (ctx
->Extensions
.ARB_half_float_vertex
)
114 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
115 case GL_UNSIGNED_INT_2_10_10_10_REV
:
116 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
117 case GL_INT_2_10_10_10_REV
:
118 return INT_2_10_10_10_REV_BIT
;
119 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
120 return UNSIGNED_INT_10F_11F_11F_REV_BIT
;
128 * Sets the VertexBinding field in the vertex attribute given by attribIndex.
131 vertex_attrib_binding(struct gl_context
*ctx
,
132 struct gl_vertex_array_object
*vao
,
136 struct gl_vertex_attrib_array
*array
= &vao
->VertexAttrib
[attribIndex
];
138 if (!_mesa_is_bufferobj(vao
->VertexBinding
[bindingIndex
].BufferObj
))
139 vao
->VertexAttribBufferMask
&= ~VERT_BIT(attribIndex
);
141 vao
->VertexAttribBufferMask
|= VERT_BIT(attribIndex
);
143 if (array
->VertexBinding
!= bindingIndex
) {
144 const GLbitfield64 array_bit
= VERT_BIT(attribIndex
);
146 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
148 vao
->VertexBinding
[array
->VertexBinding
]._BoundArrays
&= ~array_bit
;
149 vao
->VertexBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
151 array
->VertexBinding
= bindingIndex
;
153 vao
->NewArrays
|= array_bit
;
159 * Binds a buffer object to the vertex buffer binding point given by index,
160 * and sets the Offset and Stride fields.
163 _mesa_bind_vertex_buffer(struct gl_context
*ctx
,
164 struct gl_vertex_array_object
*vao
,
166 struct gl_buffer_object
*vbo
,
167 GLintptr offset
, GLsizei stride
)
169 struct gl_vertex_buffer_binding
*binding
= &vao
->VertexBinding
[index
];
171 if (binding
->BufferObj
!= vbo
||
172 binding
->Offset
!= offset
||
173 binding
->Stride
!= stride
) {
175 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
177 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
179 binding
->Offset
= offset
;
180 binding
->Stride
= stride
;
182 if (!_mesa_is_bufferobj(vbo
))
183 vao
->VertexAttribBufferMask
&= ~binding
->_BoundArrays
;
185 vao
->VertexAttribBufferMask
|= binding
->_BoundArrays
;
187 vao
->NewArrays
|= binding
->_BoundArrays
;
193 * Sets the InstanceDivisor field in the vertex buffer binding point
194 * given by bindingIndex.
197 vertex_binding_divisor(struct gl_context
*ctx
,
198 struct gl_vertex_array_object
*vao
,
202 struct gl_vertex_buffer_binding
*binding
=
203 &vao
->VertexBinding
[bindingIndex
];
205 if (binding
->InstanceDivisor
!= divisor
) {
206 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
207 binding
->InstanceDivisor
= divisor
;
208 vao
->NewArrays
|= binding
->_BoundArrays
;
214 * Examine the API profile and extensions to determine which types are legal
215 * for vertex arrays. This is called once from update_array_format().
218 get_legal_types_mask(const struct gl_context
*ctx
)
220 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
222 if (_mesa_is_gles(ctx
)) {
223 legalTypesMask
&= ~(FIXED_GL_BIT
|
225 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
227 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
228 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
229 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
230 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
231 * quite as trivial as we'd like because it uses a different enum value
232 * for GL_HALF_FLOAT_OES.
234 if (ctx
->Version
< 30) {
235 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
237 UNSIGNED_INT_2_10_10_10_REV_BIT
|
238 INT_2_10_10_10_REV_BIT
|
243 legalTypesMask
&= ~FIXED_ES_BIT
;
245 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
246 legalTypesMask
&= ~FIXED_GL_BIT
;
248 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
249 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
250 INT_2_10_10_10_REV_BIT
);
252 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
253 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
256 return legalTypesMask
;
261 * \param attrib The index of the attribute array
262 * \param size Components per element (1, 2, 3 or 4)
263 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
264 * \param format Either GL_RGBA or GL_BGRA.
265 * \param normalized Whether integer types are converted to floats in [-1, 1]
266 * \param integer Integer-valued values (will not be normalized to [-1, 1])
267 * \param doubles Double values not reduced to floats
268 * \param relativeOffset Offset of the first element relative to the binding
270 * \param flush_verties Should \c FLUSH_VERTICES be invoked before updating
274 _mesa_update_array_format(struct gl_context
*ctx
,
275 struct gl_vertex_array_object
*vao
,
276 GLuint attrib
, GLint size
, GLenum type
,
277 GLenum format
, GLboolean normalized
,
278 GLboolean integer
, GLboolean doubles
,
279 GLuint relativeOffset
, bool flush_vertices
)
281 struct gl_vertex_attrib_array
*const array
= &vao
->VertexAttrib
[attrib
];
286 if (flush_vertices
) {
287 FLUSH_VERTICES(ctx
, 0);
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 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
337 /* Compute the LegalTypesMask only once, unless the context API has
338 * changed, in which case we want to compute it again. We can't do this
339 * in _mesa_init_varrays() below because extensions are not yet enabled
342 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
343 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
346 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
348 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
349 /* BGRA ordering is not supported in ES contexts.
354 typeBit
= type_to_bit(ctx
, type
);
355 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
356 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
357 func
, _mesa_enum_to_string(type
));
361 /* Do size parameter checking.
362 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
363 * must be handled specially.
365 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
366 sizeMax
== BGRA_OR_4
&&
368 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
370 * "An INVALID_OPERATION error is generated under any of the following
373 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
374 * or UNSIGNED_INT_2_10_10_10_REV;
376 * • size is BGRA and normalized is FALSE;"
378 bool bgra_error
= false;
380 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
381 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
382 type
!= GL_INT_2_10_10_10_REV
&&
383 type
!= GL_UNSIGNED_BYTE
)
385 } else if (type
!= GL_UNSIGNED_BYTE
)
389 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
390 func
, _mesa_enum_to_string(type
));
395 _mesa_error(ctx
, GL_INVALID_OPERATION
,
396 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
403 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
404 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
408 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
409 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
410 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
411 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
415 /* The ARB_vertex_attrib_binding_spec says:
417 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
418 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
420 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
421 _mesa_error(ctx
, GL_INVALID_VALUE
,
422 "%s(relativeOffset=%d > "
423 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
424 func
, relativeOffset
);
428 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
429 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
430 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
434 _mesa_update_array_format(ctx
, vao
, attrib
, size
, type
, format
,
435 normalized
, integer
, doubles
, relativeOffset
,
443 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
446 * \param func name of calling function used for error reporting
447 * \param attrib the attribute array index to update
448 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
449 * \param sizeMin min allowable size value
450 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
451 * \param size components per element (1, 2, 3 or 4)
452 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
453 * \param stride stride between elements, in elements
454 * \param normalized are integer types converted to floats in [-1, 1]?
455 * \param integer integer-valued values (will not be normalized to [-1,1])
456 * \param doubles Double values not reduced to floats
457 * \param ptr the address (or offset inside VBO) of the array data
460 update_array(struct gl_context
*ctx
,
462 GLuint attrib
, GLbitfield legalTypesMask
,
463 GLint sizeMin
, GLint sizeMax
,
464 GLint size
, GLenum type
, GLsizei stride
,
465 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
468 struct gl_vertex_attrib_array
*array
;
469 GLsizei effectiveStride
;
471 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
473 * "Client vertex arrays - all vertex array attribute pointers must
474 * refer to buffer objects (section 2.9.2). The default vertex array
475 * object (the name zero) is also deprecated. Calling
476 * VertexAttribPointer when no buffer object or no vertex array object
477 * is bound will generate an INVALID_OPERATION error..."
479 * The check for VBOs is handled below.
481 if (ctx
->API
== API_OPENGL_CORE
482 && (ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
)) {
483 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
489 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
493 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
494 stride
> ctx
->Const
.MaxVertexAttribStride
) {
495 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
496 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
500 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
502 * "An INVALID_OPERATION error is generated under any of the following
507 * * any of the *Pointer commands specifying the location and
508 * organization of vertex array data are called while zero is bound
509 * to the ARRAY_BUFFER buffer object binding point (see section
510 * 2.9.6), and the pointer argument is not NULL."
512 if (ptr
!= NULL
&& ctx
->Array
.VAO
->ARBsemantics
&&
513 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
514 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
518 if (!update_array_format(ctx
, func
, ctx
->Array
.VAO
, attrib
,
519 legalTypesMask
, sizeMin
, sizeMax
,
520 size
, type
, normalized
, integer
, doubles
, 0)) {
524 /* Reset the vertex attrib binding */
525 vertex_attrib_binding(ctx
, ctx
->Array
.VAO
, attrib
, attrib
);
527 /* The Stride and Ptr fields are not set by update_array_format() */
528 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
529 array
->Stride
= stride
;
530 array
->Ptr
= (const GLvoid
*) ptr
;
532 /* Update the vertex buffer binding */
533 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
534 _mesa_bind_vertex_buffer(ctx
, ctx
->Array
.VAO
, attrib
,
535 ctx
->Array
.ArrayBufferObj
, (GLintptr
) ptr
,
541 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
543 GET_CURRENT_CONTEXT(ctx
);
544 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
545 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
546 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
547 DOUBLE_BIT
| HALF_BIT
|
548 UNSIGNED_INT_2_10_10_10_REV_BIT
|
549 INT_2_10_10_10_REV_BIT
);
551 FLUSH_VERTICES(ctx
, 0);
553 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
555 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
560 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
562 GET_CURRENT_CONTEXT(ctx
);
563 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
564 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
565 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
566 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
567 UNSIGNED_INT_2_10_10_10_REV_BIT
|
568 INT_2_10_10_10_REV_BIT
);
570 FLUSH_VERTICES(ctx
, 0);
572 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
574 3, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
579 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
581 GET_CURRENT_CONTEXT(ctx
);
582 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
583 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
584 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
585 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
586 INT_BIT
| UNSIGNED_INT_BIT
|
587 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
588 UNSIGNED_INT_2_10_10_10_REV_BIT
|
589 INT_2_10_10_10_REV_BIT
);
590 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
592 FLUSH_VERTICES(ctx
, 0);
594 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
595 legalTypes
, sizeMin
, BGRA_OR_4
,
596 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
601 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
603 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
604 GET_CURRENT_CONTEXT(ctx
);
606 FLUSH_VERTICES(ctx
, 0);
608 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
610 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
615 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
617 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
618 FLOAT_BIT
| DOUBLE_BIT
);
619 GET_CURRENT_CONTEXT(ctx
);
621 FLUSH_VERTICES(ctx
, 0);
623 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
625 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
630 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
631 GLsizei stride
, const GLvoid
*ptr
)
633 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
634 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
635 INT_BIT
| UNSIGNED_INT_BIT
|
636 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
637 UNSIGNED_INT_2_10_10_10_REV_BIT
|
638 INT_2_10_10_10_REV_BIT
);
639 GET_CURRENT_CONTEXT(ctx
);
641 FLUSH_VERTICES(ctx
, 0);
643 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
644 legalTypes
, 3, BGRA_OR_4
,
645 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
650 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
653 GET_CURRENT_CONTEXT(ctx
);
654 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
655 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
656 : (SHORT_BIT
| INT_BIT
|
657 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
658 UNSIGNED_INT_2_10_10_10_REV_BIT
|
659 INT_2_10_10_10_REV_BIT
);
660 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
661 const GLuint unit
= ctx
->Array
.ActiveTexture
;
663 FLUSH_VERTICES(ctx
, 0);
665 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
666 legalTypes
, sizeMin
, 4,
667 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
673 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
675 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
676 /* this is the same type that glEdgeFlag uses */
677 const GLboolean integer
= GL_FALSE
;
678 GET_CURRENT_CONTEXT(ctx
);
680 FLUSH_VERTICES(ctx
, 0);
682 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
684 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
689 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
691 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
692 GET_CURRENT_CONTEXT(ctx
);
694 FLUSH_VERTICES(ctx
, 0);
696 if (ctx
->API
!= API_OPENGLES
) {
697 _mesa_error(ctx
, GL_INVALID_OPERATION
,
698 "glPointSizePointer(ES 1.x only)");
702 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
704 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
709 * Set a generic vertex attribute array.
710 * Note that these arrays DO NOT alias the conventional GL vertex arrays
711 * (position, normal, color, fog, texcoord, etc).
714 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
715 GLboolean normalized
,
716 GLsizei stride
, const GLvoid
*ptr
)
718 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
719 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
720 INT_BIT
| UNSIGNED_INT_BIT
|
721 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
722 FIXED_ES_BIT
| FIXED_GL_BIT
|
723 UNSIGNED_INT_2_10_10_10_REV_BIT
|
724 INT_2_10_10_10_REV_BIT
|
725 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
726 GET_CURRENT_CONTEXT(ctx
);
728 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
729 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
733 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
734 legalTypes
, 1, BGRA_OR_4
,
735 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
740 * GL_EXT_gpu_shader4 / GL 3.0.
741 * Set an integer-valued vertex attribute array.
742 * Note that these arrays DO NOT alias the conventional GL vertex arrays
743 * (position, normal, color, fog, texcoord, etc).
746 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
747 GLsizei stride
, const GLvoid
*ptr
)
749 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
750 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
751 INT_BIT
| UNSIGNED_INT_BIT
);
752 const GLboolean normalized
= GL_FALSE
;
753 const GLboolean integer
= GL_TRUE
;
754 GET_CURRENT_CONTEXT(ctx
);
756 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
757 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
761 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
763 size
, type
, stride
, normalized
, integer
, GL_FALSE
, ptr
);
767 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
768 GLsizei stride
, const GLvoid
*ptr
)
770 GET_CURRENT_CONTEXT(ctx
);
771 const GLbitfield legalTypes
= (DOUBLE_BIT
);
772 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
773 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
777 update_array(ctx
, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index
),
779 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
784 _mesa_enable_vertex_array_attrib(struct gl_context
*ctx
,
785 struct gl_vertex_array_object
*vao
,
788 assert(attrib
< ARRAY_SIZE(vao
->VertexAttrib
));
790 if (!vao
->VertexAttrib
[attrib
].Enabled
) {
791 /* was disabled, now being enabled */
792 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
793 vao
->VertexAttrib
[attrib
].Enabled
= GL_TRUE
;
794 vao
->_Enabled
|= VERT_BIT(attrib
);
795 vao
->NewArrays
|= VERT_BIT(attrib
);
800 enable_vertex_array_attrib(struct gl_context
*ctx
,
801 struct gl_vertex_array_object
*vao
,
805 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
806 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
810 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
815 _mesa_EnableVertexAttribArray(GLuint index
)
817 GET_CURRENT_CONTEXT(ctx
);
818 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
819 "glEnableVertexAttribArray");
824 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
826 GET_CURRENT_CONTEXT(ctx
);
827 struct gl_vertex_array_object
*vao
;
829 /* The ARB_direct_state_access specification says:
831 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
832 * and DisableVertexArrayAttrib if <vaobj> is not
833 * [compatibility profile: zero or] the name of an existing vertex
836 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
840 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
845 disable_vertex_array_attrib(struct gl_context
*ctx
,
846 struct gl_vertex_array_object
*vao
,
850 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
851 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
855 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
857 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
858 /* was enabled, now being disabled */
859 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
860 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
861 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
862 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
868 _mesa_DisableVertexAttribArray(GLuint index
)
870 GET_CURRENT_CONTEXT(ctx
);
871 disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
872 "glDisableVertexAttribArray");
877 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
879 GET_CURRENT_CONTEXT(ctx
);
880 struct gl_vertex_array_object
*vao
;
882 /* The ARB_direct_state_access specification says:
884 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
885 * and DisableVertexArrayAttrib if <vaobj> is not
886 * [compatibility profile: zero or] the name of an existing vertex
889 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
893 disable_vertex_array_attrib(ctx
, vao
, index
, "glDisableVertexArrayAttrib");
898 * Return info for a vertex attribute array (no alias with legacy
899 * vertex attributes (pos, normal, color, etc)). This function does
900 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
903 get_vertex_array_attrib(struct gl_context
*ctx
,
904 const struct gl_vertex_array_object
*vao
,
905 GLuint index
, GLenum pname
,
908 const struct gl_vertex_attrib_array
*array
;
910 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
911 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
915 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
917 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
920 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
921 return array
->Enabled
;
922 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
923 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
924 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
925 return array
->Stride
;
926 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
928 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
929 return array
->Normalized
;
930 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
931 return vao
->VertexBinding
[array
->VertexBinding
].BufferObj
->Name
;
932 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
933 if ((_mesa_is_desktop_gl(ctx
)
934 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
935 || _mesa_is_gles3(ctx
)) {
936 return array
->Integer
;
939 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
940 if (_mesa_is_desktop_gl(ctx
)) {
941 return array
->Doubles
;
944 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
945 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
946 || _mesa_is_gles3(ctx
)) {
947 return vao
->VertexBinding
[array
->VertexBinding
].InstanceDivisor
;
950 case GL_VERTEX_ATTRIB_BINDING
:
951 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
952 return array
->VertexBinding
- VERT_ATTRIB_GENERIC0
;
955 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
956 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
957 return array
->RelativeOffset
;
965 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
970 static const GLfloat
*
971 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
974 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
975 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
979 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
980 _mesa_error(ctx
, GL_INVALID_VALUE
,
981 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
985 assert(VERT_ATTRIB_GENERIC(index
) <
986 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
988 FLUSH_CURRENT(ctx
, 0);
989 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
993 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
995 GET_CURRENT_CONTEXT(ctx
);
997 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
998 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
1004 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1006 "glGetVertexAttribfv");
1012 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1014 GET_CURRENT_CONTEXT(ctx
);
1016 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1017 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
1019 params
[0] = (GLdouble
) v
[0];
1020 params
[1] = (GLdouble
) v
[1];
1021 params
[2] = (GLdouble
) v
[2];
1022 params
[3] = (GLdouble
) v
[3];
1026 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1028 "glGetVertexAttribdv");
1033 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1035 GET_CURRENT_CONTEXT(ctx
);
1037 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1039 (const GLdouble
*)get_current_attrib(ctx
, index
,
1040 "glGetVertexAttribLdv");
1049 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1051 "glGetVertexAttribLdv");
1056 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
1058 GET_CURRENT_CONTEXT(ctx
);
1060 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1061 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1063 /* XXX should floats in[0,1] be scaled to full int range? */
1064 params
[0] = (GLint
) v
[0];
1065 params
[1] = (GLint
) v
[1];
1066 params
[2] = (GLint
) v
[2];
1067 params
[3] = (GLint
) v
[3];
1071 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1073 "glGetVertexAttribiv");
1080 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1082 GET_CURRENT_CONTEXT(ctx
);
1084 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1085 const GLint
*v
= (const GLint
*)
1086 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1092 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1094 "glGetVertexAttribIiv");
1101 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1103 GET_CURRENT_CONTEXT(ctx
);
1105 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1106 const GLuint
*v
= (const GLuint
*)
1107 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1113 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1115 "glGetVertexAttribIuiv");
1121 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1123 GET_CURRENT_CONTEXT(ctx
);
1125 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1126 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1130 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1131 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1135 assert(VERT_ATTRIB_GENERIC(index
) <
1136 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1138 *pointer
= (GLvoid
*)
1139 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1143 /** ARB_direct_state_access */
1145 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
1146 GLenum pname
, GLint
*params
)
1148 GET_CURRENT_CONTEXT(ctx
);
1149 struct gl_vertex_array_object
*vao
;
1151 /* The ARB_direct_state_access specification says:
1153 * "An INVALID_OPERATION error is generated if <vaobj> is not
1154 * [compatibility profile: zero or] the name of an existing
1155 * vertex array object."
1157 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexediv");
1161 /* The ARB_direct_state_access specification says:
1163 * "For GetVertexArrayIndexediv, <pname> must be one of
1164 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1165 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1166 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1167 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1168 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1172 * "Add GetVertexArrayIndexediv in 'Get Command' for
1173 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1174 * VERTEX_ATTRIB_BINDING,
1175 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1176 * VERTEX_BINDING_OFFSET, and
1177 * VERTEX_BINDING_STRIDE states"
1179 * The only parameter name common to both lists is
1180 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1181 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1182 * pretty clear however that the intent is that it should be possible
1183 * to query all vertex attrib and binding states that can be set with
1187 case GL_VERTEX_BINDING_OFFSET
:
1188 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1190 case GL_VERTEX_BINDING_STRIDE
:
1191 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
1193 case GL_VERTEX_BINDING_DIVISOR
:
1194 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
1196 case GL_VERTEX_BINDING_BUFFER
:
1197 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
1200 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
1201 "glGetVertexArrayIndexediv");
1208 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
1209 GLenum pname
, GLint64
*params
)
1211 GET_CURRENT_CONTEXT(ctx
);
1212 struct gl_vertex_array_object
*vao
;
1214 /* The ARB_direct_state_access specification says:
1216 * "An INVALID_OPERATION error is generated if <vaobj> is not
1217 * [compatibility profile: zero or] the name of an existing
1218 * vertex array object."
1220 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexed64iv");
1224 /* The ARB_direct_state_access specification says:
1226 * "For GetVertexArrayIndexed64iv, <pname> must be
1227 * VERTEX_BINDING_OFFSET."
1231 * "An INVALID_ENUM error is generated if <pname> is not one of
1232 * the valid values listed above for the corresponding command."
1234 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
1235 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
1236 "pname != GL_VERTEX_BINDING_OFFSET)");
1240 /* The ARB_direct_state_access specification says:
1242 * "An INVALID_VALUE error is generated if <index> is greater than
1243 * or equal to the value of MAX_VERTEX_ATTRIBS."
1245 * Since the index refers to a buffer binding in this case, the intended
1246 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1247 * required to be the same, so in practice this doesn't matter.
1249 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
1250 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
1251 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1252 index
, ctx
->Const
.MaxVertexAttribBindings
);
1256 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1261 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1262 GLsizei count
, const GLvoid
*ptr
)
1265 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1270 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1274 _mesa_NormalPointer(type
, stride
, ptr
);
1279 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1283 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1288 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1292 _mesa_IndexPointer(type
, stride
, ptr
);
1297 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1298 GLsizei count
, const GLvoid
*ptr
)
1301 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1306 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1309 _mesa_EdgeFlagPointer(stride
, ptr
);
1314 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1316 GET_CURRENT_CONTEXT(ctx
);
1317 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1318 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1319 GLenum ctype
= 0; /* color type */
1320 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1321 const GLint toffset
= 0; /* always zero */
1322 GLint defstride
; /* default stride */
1325 FLUSH_VERTICES(ctx
, 0);
1327 f
= sizeof(GLfloat
);
1328 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1331 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1337 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1338 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1343 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1344 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1349 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1350 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1351 ctype
= GL_UNSIGNED_BYTE
;
1354 defstride
= c
+ 2*f
;
1357 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1358 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1359 ctype
= GL_UNSIGNED_BYTE
;
1362 defstride
= c
+ 3*f
;
1365 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1366 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1373 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1374 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1379 case GL_C4F_N3F_V3F
:
1380 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1381 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1389 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1390 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1395 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1396 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1400 case GL_T2F_C4UB_V3F
:
1401 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1402 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1403 ctype
= GL_UNSIGNED_BYTE
;
1408 case GL_T2F_C3F_V3F
:
1409 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1410 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1416 case GL_T2F_N3F_V3F
:
1417 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1418 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1423 case GL_T2F_C4F_N3F_V3F
:
1424 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1425 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1432 case GL_T4F_C4F_N3F_V4F
:
1433 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1434 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1442 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1450 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1451 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1452 /* XXX also disable secondary color and generic arrays? */
1456 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1457 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1458 (GLubyte
*) pointer
+ toffset
);
1461 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1466 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1467 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1468 (GLubyte
*) pointer
+ coffset
);
1471 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1477 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1478 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1481 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1485 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1486 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1487 (GLubyte
*) pointer
+ voffset
);
1492 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1494 GET_CURRENT_CONTEXT(ctx
);
1496 FLUSH_VERTICES(ctx
, 0);
1498 if (MESA_VERBOSE
& VERBOSE_API
)
1499 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1502 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1506 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1509 if (ctx
->Array
.LockCount
!= 0) {
1510 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1514 ctx
->Array
.LockFirst
= first
;
1515 ctx
->Array
.LockCount
= count
;
1517 ctx
->NewState
|= _NEW_ARRAY
;
1522 _mesa_UnlockArraysEXT( void )
1524 GET_CURRENT_CONTEXT(ctx
);
1526 FLUSH_VERTICES(ctx
, 0);
1528 if (MESA_VERBOSE
& VERBOSE_API
)
1529 _mesa_debug(ctx
, "glUnlockArrays\n");
1531 if (ctx
->Array
.LockCount
== 0) {
1532 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1536 ctx
->Array
.LockFirst
= 0;
1537 ctx
->Array
.LockCount
= 0;
1538 ctx
->NewState
|= _NEW_ARRAY
;
1542 /* GL_EXT_multi_draw_arrays */
1544 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1545 const GLsizei
*count
, GLsizei primcount
)
1547 GET_CURRENT_CONTEXT(ctx
);
1550 FLUSH_VERTICES(ctx
, 0);
1552 for (i
= 0; i
< primcount
; i
++) {
1554 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1560 /* GL_IBM_multimode_draw_arrays */
1562 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1563 const GLsizei
* count
,
1564 GLsizei primcount
, GLint modestride
)
1566 GET_CURRENT_CONTEXT(ctx
);
1569 FLUSH_VERTICES(ctx
, 0);
1571 for ( i
= 0 ; i
< primcount
; i
++ ) {
1572 if ( count
[i
] > 0 ) {
1573 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1574 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1580 /* GL_IBM_multimode_draw_arrays */
1582 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1583 GLenum type
, const GLvoid
* const * indices
,
1584 GLsizei primcount
, GLint modestride
)
1586 GET_CURRENT_CONTEXT(ctx
);
1589 FLUSH_VERTICES(ctx
, 0);
1591 /* XXX not sure about ARB_vertex_buffer_object handling here */
1593 for ( i
= 0 ; i
< primcount
; i
++ ) {
1594 if ( count
[i
] > 0 ) {
1595 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1596 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1604 * GL_NV_primitive_restart and GL 3.1
1607 _mesa_PrimitiveRestartIndex(GLuint index
)
1609 GET_CURRENT_CONTEXT(ctx
);
1611 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1612 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1616 if (ctx
->Array
.RestartIndex
!= index
) {
1617 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1618 ctx
->Array
.RestartIndex
= index
;
1624 * See GL_ARB_instanced_arrays.
1625 * Note that the instance divisor only applies to generic arrays, not
1626 * the legacy vertex arrays.
1629 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1631 GET_CURRENT_CONTEXT(ctx
);
1633 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1634 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1636 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1637 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1641 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1642 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1647 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
1649 /* The ARB_vertex_attrib_binding spec says:
1653 * void VertexAttribDivisor(uint index, uint divisor);
1655 * is equivalent to (assuming no errors are generated):
1657 * VertexAttribBinding(index, index);
1658 * VertexBindingDivisor(index, divisor);"
1660 vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
1661 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
1666 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1668 /* From the OpenGL 4.3 core specification, page 302:
1669 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1670 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1673 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1675 case GL_UNSIGNED_BYTE
:
1677 case GL_UNSIGNED_SHORT
:
1679 case GL_UNSIGNED_INT
:
1682 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1686 return ctx
->Array
.RestartIndex
;
1691 * GL_ARB_vertex_attrib_binding
1694 vertex_array_vertex_buffer(struct gl_context
*ctx
,
1695 struct gl_vertex_array_object
*vao
,
1696 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1697 GLsizei stride
, const char *func
)
1699 struct gl_buffer_object
*vbo
;
1701 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1703 /* The ARB_vertex_attrib_binding spec says:
1705 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1706 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1708 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1709 _mesa_error(ctx
, GL_INVALID_VALUE
,
1710 "%s(bindingindex=%u > "
1711 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1712 func
, bindingIndex
);
1716 /* The ARB_vertex_attrib_binding spec says:
1718 * "The error INVALID_VALUE is generated if <stride> or <offset>
1722 _mesa_error(ctx
, GL_INVALID_VALUE
,
1723 "%s(offset=%" PRId64
" < 0)",
1724 func
, (int64_t) offset
);
1729 _mesa_error(ctx
, GL_INVALID_VALUE
,
1730 "%s(stride=%d < 0)", func
, stride
);
1734 if (((ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
1735 stride
> ctx
->Const
.MaxVertexAttribStride
) {
1736 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
1737 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
1742 vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1743 vbo
= vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1744 } else if (buffer
!= 0) {
1745 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1747 if (!vbo
&& _mesa_is_gles31(ctx
)) {
1748 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", func
);
1751 /* From the GL_ARB_vertex_attrib_array spec:
1753 * "[Core profile only:]
1754 * An INVALID_OPERATION error is generated if buffer is not zero or a
1755 * name returned from a previous call to GenBuffers, or if such a name
1756 * has since been deleted with DeleteBuffers.
1758 * Otherwise, we fall back to the same compat profile behavior as other
1759 * object references (automatically gen it).
1761 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
1764 /* The ARB_vertex_attrib_binding spec says:
1766 * "If <buffer> is zero, any buffer object attached to this
1767 * bindpoint is detached."
1769 vbo
= ctx
->Shared
->NullBufferObj
;
1772 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
1773 vbo
, offset
, stride
);
1778 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1781 GET_CURRENT_CONTEXT(ctx
);
1783 /* The ARB_vertex_attrib_binding spec says:
1785 * "An INVALID_OPERATION error is generated if no vertex array object
1788 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
1789 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1790 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1791 "glBindVertexBuffer(No array object bound)");
1795 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
1796 buffer
, offset
, stride
, "glBindVertexBuffer");
1801 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
1802 GLintptr offset
, GLsizei stride
)
1804 GET_CURRENT_CONTEXT(ctx
);
1805 struct gl_vertex_array_object
*vao
;
1807 /* The ARB_direct_state_access specification says:
1809 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1810 * if <vaobj> is not [compatibility profile: zero or] the name of an
1811 * existing vertex array object."
1813 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
1817 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
,
1818 buffer
, offset
, stride
,
1819 "glVertexArrayVertexBuffer");
1824 vertex_array_vertex_buffers(struct gl_context
*ctx
,
1825 struct gl_vertex_array_object
*vao
,
1826 GLuint first
, GLsizei count
, const GLuint
*buffers
,
1827 const GLintptr
*offsets
, const GLsizei
*strides
,
1832 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1834 /* The ARB_multi_bind spec says:
1836 * "An INVALID_OPERATION error is generated if <first> + <count>
1837 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1839 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1840 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1841 "%s(first=%u + count=%d > the value of "
1842 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1843 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1849 * The ARB_multi_bind spec says:
1851 * "If <buffers> is NULL, each affected vertex buffer binding point
1852 * from <first> through <first>+<count>-1 will be reset to have no
1853 * bound buffer object. In this case, the offsets and strides
1854 * associated with the binding points are set to default values,
1855 * ignoring <offsets> and <strides>."
1857 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1859 for (i
= 0; i
< count
; i
++)
1860 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1866 /* Note that the error semantics for multi-bind commands differ from
1867 * those of other GL commands.
1869 * The Issues section in the ARB_multi_bind spec says:
1871 * "(11) Typically, OpenGL specifies that if an error is generated by
1872 * a command, that command has no effect. This is somewhat
1873 * unfortunate for multi-bind commands, because it would require
1874 * a first pass to scan the entire list of bound objects for
1875 * errors and then a second pass to actually perform the
1876 * bindings. Should we have different error semantics?
1878 * RESOLVED: Yes. In this specification, when the parameters for
1879 * one of the <count> binding points are invalid, that binding
1880 * point is not updated and an error will be generated. However,
1881 * other binding points in the same command will be updated if
1882 * their parameters are valid and no other error occurs."
1885 _mesa_begin_bufferobj_lookups(ctx
);
1887 for (i
= 0; i
< count
; i
++) {
1888 struct gl_buffer_object
*vbo
;
1890 /* The ARB_multi_bind spec says:
1892 * "An INVALID_VALUE error is generated if any value in
1893 * <offsets> or <strides> is negative (per binding)."
1895 if (offsets
[i
] < 0) {
1896 _mesa_error(ctx
, GL_INVALID_VALUE
,
1897 "%s(offsets[%u]=%" PRId64
" < 0)",
1898 func
, i
, (int64_t) offsets
[i
]);
1902 if (strides
[i
] < 0) {
1903 _mesa_error(ctx
, GL_INVALID_VALUE
,
1904 "%s(strides[%u]=%d < 0)",
1905 func
, i
, strides
[i
]);
1909 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1910 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
1911 _mesa_error(ctx
, GL_INVALID_VALUE
,
1912 "%s(strides[%u]=%d > "
1913 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
1918 struct gl_vertex_buffer_binding
*binding
=
1919 &vao
->VertexBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1921 if (buffers
[i
] == binding
->BufferObj
->Name
)
1922 vbo
= binding
->BufferObj
;
1924 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
1929 vbo
= ctx
->Shared
->NullBufferObj
;
1932 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1933 vbo
, offsets
[i
], strides
[i
]);
1936 _mesa_end_bufferobj_lookups(ctx
);
1941 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1942 const GLintptr
*offsets
, const GLsizei
*strides
)
1944 GET_CURRENT_CONTEXT(ctx
);
1946 /* The ARB_vertex_attrib_binding spec says:
1948 * "An INVALID_OPERATION error is generated if no
1949 * vertex array object is bound."
1951 if (ctx
->API
== API_OPENGL_CORE
&&
1952 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1953 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1954 "glBindVertexBuffers(No array object bound)");
1958 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
1959 buffers
, offsets
, strides
,
1960 "glBindVertexBuffers");
1965 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
1966 const GLuint
*buffers
,
1967 const GLintptr
*offsets
, const GLsizei
*strides
)
1969 GET_CURRENT_CONTEXT(ctx
);
1970 struct gl_vertex_array_object
*vao
;
1972 /* The ARB_direct_state_access specification says:
1974 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1975 * if <vaobj> is not [compatibility profile: zero or] the name of an
1976 * existing vertex array object."
1978 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
1982 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
1983 buffers
, offsets
, strides
,
1984 "glVertexArrayVertexBuffers");
1989 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
1990 GLboolean normalized
, GLboolean integer
,
1991 GLboolean doubles
, GLbitfield legalTypes
,
1992 GLsizei maxSize
, GLuint relativeOffset
,
1995 GET_CURRENT_CONTEXT(ctx
);
1996 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1998 /* The ARB_vertex_attrib_binding spec says:
2000 * "An INVALID_OPERATION error is generated under any of the following
2002 * - if no vertex array object is currently bound (see section 2.10);
2005 * This error condition only applies to VertexAttribFormat and
2006 * VertexAttribIFormat in the extension spec, but we assume that this
2007 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2008 * to all three functions.
2010 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2011 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2012 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2013 "%s(No array object bound)", func
);
2017 /* The ARB_vertex_attrib_binding spec says:
2019 * "The error INVALID_VALUE is generated if index is greater than or equal
2020 * to the value of MAX_VERTEX_ATTRIBS."
2022 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2023 _mesa_error(ctx
, GL_INVALID_VALUE
,
2024 "%s(attribindex=%u > "
2025 "GL_MAX_VERTEX_ATTRIBS)",
2030 FLUSH_VERTICES(ctx
, 0);
2032 update_array_format(ctx
, func
, ctx
->Array
.VAO
,
2033 VERT_ATTRIB_GENERIC(attribIndex
),
2034 legalTypes
, 1, maxSize
, size
, type
,
2035 normalized
, integer
, doubles
, relativeOffset
);
2040 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2041 GLboolean normalized
, GLuint relativeOffset
)
2043 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
2044 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2045 BGRA_OR_4
, relativeOffset
,
2046 "glVertexAttribFormat");
2051 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2052 GLuint relativeOffset
)
2054 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
2055 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
2056 relativeOffset
, "glVertexAttribIFormat");
2061 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2062 GLuint relativeOffset
)
2064 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
2065 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
2066 relativeOffset
, "glVertexAttribLFormat");
2071 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2072 GLenum type
, GLboolean normalized
,
2073 GLboolean integer
, GLboolean doubles
,
2074 GLbitfield legalTypes
, GLsizei maxSize
,
2075 GLuint relativeOffset
, const char *func
)
2077 GET_CURRENT_CONTEXT(ctx
);
2078 struct gl_vertex_array_object
*vao
;
2080 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2082 /* The ARB_direct_state_access spec says:
2084 * "An INVALID_OPERATION error is generated by VertexArrayAttrib*Format
2085 * if <vaobj> is not [compatibility profile: zero or] the name of an
2086 * existing vertex array object."
2088 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
2092 /* The ARB_vertex_attrib_binding spec says:
2094 * "The error INVALID_VALUE is generated if index is greater than or equal
2095 * to the value of MAX_VERTEX_ATTRIBS."
2097 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2098 _mesa_error(ctx
, GL_INVALID_VALUE
,
2099 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2104 FLUSH_VERTICES(ctx
, 0);
2106 update_array_format(ctx
, func
, vao
,
2107 VERT_ATTRIB_GENERIC(attribIndex
),
2108 legalTypes
, 1, maxSize
, size
, type
, normalized
,
2109 integer
, doubles
, relativeOffset
);
2114 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2115 GLenum type
, GLboolean normalized
,
2116 GLuint relativeOffset
)
2118 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
2119 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2120 BGRA_OR_4
, relativeOffset
,
2121 "glVertexArrayAttribFormat");
2126 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
2127 GLint size
, GLenum type
,
2128 GLuint relativeOffset
)
2130 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2131 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
2133 "glVertexArrayAttribIFormat");
2138 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
2139 GLint size
, GLenum type
,
2140 GLuint relativeOffset
)
2142 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2143 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
2145 "glVertexArrayAttribLFormat");
2150 vertex_array_attrib_binding(struct gl_context
*ctx
,
2151 struct gl_vertex_array_object
*vao
,
2152 GLuint attribIndex
, GLuint bindingIndex
,
2155 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2157 /* The ARB_vertex_attrib_binding spec says:
2159 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2160 * <bindingindex> must be less than the value of
2161 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2164 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2165 _mesa_error(ctx
, GL_INVALID_VALUE
,
2166 "%s(attribindex=%u >= "
2167 "GL_MAX_VERTEX_ATTRIBS)",
2172 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2173 _mesa_error(ctx
, GL_INVALID_VALUE
,
2174 "%s(bindingindex=%u >= "
2175 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2176 func
, bindingIndex
);
2180 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
2182 vertex_attrib_binding(ctx
, vao
,
2183 VERT_ATTRIB_GENERIC(attribIndex
),
2184 VERT_ATTRIB_GENERIC(bindingIndex
));
2189 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2191 GET_CURRENT_CONTEXT(ctx
);
2193 /* The ARB_vertex_attrib_binding spec says:
2195 * "An INVALID_OPERATION error is generated if no vertex array object
2198 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2199 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2200 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2201 "glVertexAttribBinding(No array object bound)");
2205 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2206 attribIndex
, bindingIndex
,
2207 "glVertexAttribBinding");
2212 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2214 GET_CURRENT_CONTEXT(ctx
);
2215 struct gl_vertex_array_object
*vao
;
2217 /* The ARB_direct_state_access specification says:
2219 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2220 * if <vaobj> is not [compatibility profile: zero or] the name of an
2221 * existing vertex array object."
2223 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2227 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2228 "glVertexArrayAttribBinding");
2233 vertex_array_binding_divisor(struct gl_context
*ctx
,
2234 struct gl_vertex_array_object
*vao
,
2235 GLuint bindingIndex
, GLuint divisor
,
2238 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2240 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2241 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
2245 /* The ARB_vertex_attrib_binding spec says:
2247 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2248 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2250 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2251 _mesa_error(ctx
, GL_INVALID_VALUE
,
2252 "%s(bindingindex=%u > "
2253 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2254 func
, bindingIndex
);
2258 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2263 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2265 GET_CURRENT_CONTEXT(ctx
);
2267 /* The ARB_vertex_attrib_binding spec says:
2269 * "An INVALID_OPERATION error is generated if no vertex array object
2272 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2273 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2274 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2275 "glVertexBindingDivisor(No array object bound)");
2279 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
2280 bindingIndex
, divisor
,
2281 "glVertexBindingDivisor");
2286 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
2289 struct gl_vertex_array_object
*vao
;
2290 GET_CURRENT_CONTEXT(ctx
);
2292 /* The ARB_direct_state_access specification says:
2294 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2295 * if <vaobj> is not [compatibility profile: zero or] the name of an
2296 * existing vertex array object."
2298 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayBindingDivisor");
2302 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
2303 "glVertexArrayBindingDivisor");
2308 * Copy one client vertex array to another.
2311 _mesa_copy_client_array(struct gl_context
*ctx
,
2312 struct gl_client_array
*dst
,
2313 struct gl_client_array
*src
)
2315 dst
->Size
= src
->Size
;
2316 dst
->Type
= src
->Type
;
2317 dst
->Format
= src
->Format
;
2318 dst
->Stride
= src
->Stride
;
2319 dst
->StrideB
= src
->StrideB
;
2320 dst
->Ptr
= src
->Ptr
;
2321 dst
->Enabled
= src
->Enabled
;
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_vertex_attrib_array
*dst
,
2333 const struct gl_vertex_attrib_array
*src
)
2335 dst
->Size
= src
->Size
;
2336 dst
->Type
= src
->Type
;
2337 dst
->Format
= src
->Format
;
2338 dst
->VertexBinding
= src
->VertexBinding
;
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 vertex array's fields.
2366 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
2369 fprintf(stderr
, " %s[%d]: ", name
, index
);
2371 fprintf(stderr
, " %s: ", name
);
2372 fprintf(stderr
, "Ptr=%p, Type=%s, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
2373 array
->Ptr
, _mesa_enum_to_string(array
->Type
), array
->Size
,
2374 array
->_ElementSize
, array
->StrideB
, array
->BufferObj
->Name
,
2375 (unsigned long) array
->BufferObj
->Size
);
2380 * Print current vertex object/array info. For debug.
2383 _mesa_print_arrays(struct gl_context
*ctx
)
2385 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2388 printf("Array Object %u\n", vao
->Name
);
2389 if (vao
->_VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
2390 print_array("Vertex", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_POS
]);
2391 if (vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
2392 print_array("Normal", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
]);
2393 if (vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
2394 print_array("Color", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
]);
2395 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
2396 if (vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
2397 print_array("TexCoord", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
2398 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
2399 if (vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
2400 print_array("Attrib", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
2405 * Initialize vertex array state for given context.
2408 _mesa_init_varray(struct gl_context
*ctx
)
2410 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
2411 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2412 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2414 ctx
->Array
.Objects
= _mesa_NewHashTable();
2419 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2422 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2424 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2425 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2426 _mesa_delete_vao(ctx
, vao
);
2431 * Free vertex array state for given context.
2434 _mesa_free_varray_data(struct gl_context
*ctx
)
2436 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2437 _mesa_DeleteHashTable(ctx
->Array
.Objects
);