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 (array
->VertexBinding
!= bindingIndex
) {
139 const GLbitfield64 array_bit
= VERT_BIT(attribIndex
);
141 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
143 vao
->VertexBinding
[array
->VertexBinding
]._BoundArrays
&= ~array_bit
;
144 vao
->VertexBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
146 array
->VertexBinding
= bindingIndex
;
148 vao
->NewArrays
|= array_bit
;
154 * Binds a buffer object to the vertex buffer binding point given by index,
155 * and sets the Offset and Stride fields.
158 _mesa_bind_vertex_buffer(struct gl_context
*ctx
,
159 struct gl_vertex_array_object
*vao
,
161 struct gl_buffer_object
*vbo
,
162 GLintptr offset
, GLsizei stride
)
164 struct gl_vertex_buffer_binding
*binding
= &vao
->VertexBinding
[index
];
166 if (binding
->BufferObj
!= vbo
||
167 binding
->Offset
!= offset
||
168 binding
->Stride
!= stride
) {
170 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
172 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
174 binding
->Offset
= offset
;
175 binding
->Stride
= stride
;
177 vao
->NewArrays
|= binding
->_BoundArrays
;
183 * Sets the InstanceDivisor field in the vertex buffer binding point
184 * given by bindingIndex.
187 vertex_binding_divisor(struct gl_context
*ctx
,
188 struct gl_vertex_array_object
*vao
,
192 struct gl_vertex_buffer_binding
*binding
=
193 &vao
->VertexBinding
[bindingIndex
];
195 if (binding
->InstanceDivisor
!= divisor
) {
196 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
197 binding
->InstanceDivisor
= divisor
;
198 vao
->NewArrays
|= binding
->_BoundArrays
;
204 * Examine the API profile and extensions to determine which types are legal
205 * for vertex arrays. This is called once from update_array_format().
208 get_legal_types_mask(const struct gl_context
*ctx
)
210 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
212 if (_mesa_is_gles(ctx
)) {
213 legalTypesMask
&= ~(FIXED_GL_BIT
|
215 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
217 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
218 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
219 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
220 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
221 * quite as trivial as we'd like because it uses a different enum value
222 * for GL_HALF_FLOAT_OES.
224 if (ctx
->Version
< 30) {
225 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
227 UNSIGNED_INT_2_10_10_10_REV_BIT
|
228 INT_2_10_10_10_REV_BIT
|
233 legalTypesMask
&= ~FIXED_ES_BIT
;
235 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
236 legalTypesMask
&= ~FIXED_GL_BIT
;
238 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
239 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
240 INT_2_10_10_10_REV_BIT
);
242 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
243 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
246 return legalTypesMask
;
251 * Does error checking and updates the format in an attrib array.
253 * Called by update_array() and VertexAttrib*Format().
255 * \param func Name of calling function used for error reporting
256 * \param attrib The index of the attribute array
257 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
258 * \param sizeMin Min allowable size value
259 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
260 * \param size Components per element (1, 2, 3 or 4)
261 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
262 * \param normalized Whether integer types are converted to floats in [-1, 1]
263 * \param integer Integer-valued values (will not be normalized to [-1, 1])
264 * \param doubles Double values not reduced to floats
265 * \param relativeOffset Offset of the first element relative to the binding offset.
268 update_array_format(struct gl_context
*ctx
,
270 struct gl_vertex_array_object
*vao
,
271 GLuint attrib
, GLbitfield legalTypesMask
,
272 GLint sizeMin
, GLint sizeMax
,
273 GLint size
, GLenum type
,
274 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
275 GLuint relativeOffset
)
277 struct gl_vertex_attrib_array
*array
;
280 GLenum format
= GL_RGBA
;
282 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
283 /* Compute the LegalTypesMask only once, unless the context API has
284 * changed, in which case we want to compute it again. We can't do this
285 * in _mesa_init_varrays() below because extensions are not yet enabled
288 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
289 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
292 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
294 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
295 /* BGRA ordering is not supported in ES contexts.
300 typeBit
= type_to_bit(ctx
, type
);
301 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
302 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
303 func
, _mesa_enum_to_string(type
));
307 /* Do size parameter checking.
308 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
309 * must be handled specially.
311 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
312 sizeMax
== BGRA_OR_4
&&
314 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
316 * "An INVALID_OPERATION error is generated under any of the following
319 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
320 * or UNSIGNED_INT_2_10_10_10_REV;
322 * • size is BGRA and normalized is FALSE;"
324 bool bgra_error
= false;
326 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
327 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
328 type
!= GL_INT_2_10_10_10_REV
&&
329 type
!= GL_UNSIGNED_BYTE
)
331 } else if (type
!= GL_UNSIGNED_BYTE
)
335 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
336 func
, _mesa_enum_to_string(type
));
341 _mesa_error(ctx
, GL_INVALID_OPERATION
,
342 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
349 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
350 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
354 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
355 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
356 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
357 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
361 /* The ARB_vertex_attrib_binding_spec says:
363 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
364 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
366 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
367 _mesa_error(ctx
, GL_INVALID_VALUE
,
368 "%s(relativeOffset=%d > "
369 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
370 func
, relativeOffset
);
374 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
375 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
376 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
382 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
383 assert(elementSize
!= -1);
385 array
= &vao
->VertexAttrib
[attrib
];
388 array
->Format
= format
;
389 array
->Normalized
= normalized
;
390 array
->Integer
= integer
;
391 array
->Doubles
= doubles
;
392 array
->RelativeOffset
= relativeOffset
;
393 array
->_ElementSize
= elementSize
;
395 vao
->NewArrays
|= VERT_BIT(attrib
);
396 ctx
->NewState
|= _NEW_ARRAY
;
403 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
406 * \param func name of calling function used for error reporting
407 * \param attrib the attribute array index to update
408 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
409 * \param sizeMin min allowable size value
410 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
411 * \param size components per element (1, 2, 3 or 4)
412 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
413 * \param stride stride between elements, in elements
414 * \param normalized are integer types converted to floats in [-1, 1]?
415 * \param integer integer-valued values (will not be normalized to [-1,1])
416 * \param doubles Double values not reduced to floats
417 * \param ptr the address (or offset inside VBO) of the array data
420 update_array(struct gl_context
*ctx
,
422 GLuint attrib
, GLbitfield legalTypesMask
,
423 GLint sizeMin
, GLint sizeMax
,
424 GLint size
, GLenum type
, GLsizei stride
,
425 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
428 struct gl_vertex_attrib_array
*array
;
429 GLsizei effectiveStride
;
431 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
433 * "Client vertex arrays - all vertex array attribute pointers must
434 * refer to buffer objects (section 2.9.2). The default vertex array
435 * object (the name zero) is also deprecated. Calling
436 * VertexAttribPointer when no buffer object or no vertex array object
437 * is bound will generate an INVALID_OPERATION error..."
439 * The check for VBOs is handled below.
441 if (ctx
->API
== API_OPENGL_CORE
442 && (ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
)) {
443 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
449 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
453 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
454 stride
> ctx
->Const
.MaxVertexAttribStride
) {
455 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
456 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
460 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
462 * "An INVALID_OPERATION error is generated under any of the following
467 * * any of the *Pointer commands specifying the location and
468 * organization of vertex array data are called while zero is bound
469 * to the ARRAY_BUFFER buffer object binding point (see section
470 * 2.9.6), and the pointer argument is not NULL."
472 if (ptr
!= NULL
&& ctx
->Array
.VAO
->ARBsemantics
&&
473 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
474 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
478 if (!update_array_format(ctx
, func
, ctx
->Array
.VAO
, attrib
,
479 legalTypesMask
, sizeMin
, sizeMax
,
480 size
, type
, normalized
, integer
, doubles
, 0)) {
484 /* Reset the vertex attrib binding */
485 vertex_attrib_binding(ctx
, ctx
->Array
.VAO
, attrib
, attrib
);
487 /* The Stride and Ptr fields are not set by update_array_format() */
488 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
489 array
->Stride
= stride
;
490 array
->Ptr
= (const GLvoid
*) ptr
;
492 /* Update the vertex buffer binding */
493 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
494 _mesa_bind_vertex_buffer(ctx
, ctx
->Array
.VAO
, attrib
,
495 ctx
->Array
.ArrayBufferObj
, (GLintptr
) ptr
,
501 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
503 GET_CURRENT_CONTEXT(ctx
);
504 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
505 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
506 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
507 DOUBLE_BIT
| HALF_BIT
|
508 UNSIGNED_INT_2_10_10_10_REV_BIT
|
509 INT_2_10_10_10_REV_BIT
);
511 FLUSH_VERTICES(ctx
, 0);
513 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
515 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
520 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
522 GET_CURRENT_CONTEXT(ctx
);
523 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
524 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
525 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
526 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
527 UNSIGNED_INT_2_10_10_10_REV_BIT
|
528 INT_2_10_10_10_REV_BIT
);
530 FLUSH_VERTICES(ctx
, 0);
532 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
534 3, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
539 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
541 GET_CURRENT_CONTEXT(ctx
);
542 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
543 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
544 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
545 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
546 INT_BIT
| UNSIGNED_INT_BIT
|
547 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
548 UNSIGNED_INT_2_10_10_10_REV_BIT
|
549 INT_2_10_10_10_REV_BIT
);
550 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
552 FLUSH_VERTICES(ctx
, 0);
554 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
555 legalTypes
, sizeMin
, BGRA_OR_4
,
556 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
561 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
563 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
564 GET_CURRENT_CONTEXT(ctx
);
566 FLUSH_VERTICES(ctx
, 0);
568 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
570 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
575 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
577 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
578 FLOAT_BIT
| DOUBLE_BIT
);
579 GET_CURRENT_CONTEXT(ctx
);
581 FLUSH_VERTICES(ctx
, 0);
583 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
585 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
590 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
591 GLsizei stride
, const GLvoid
*ptr
)
593 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
594 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
595 INT_BIT
| UNSIGNED_INT_BIT
|
596 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
597 UNSIGNED_INT_2_10_10_10_REV_BIT
|
598 INT_2_10_10_10_REV_BIT
);
599 GET_CURRENT_CONTEXT(ctx
);
601 FLUSH_VERTICES(ctx
, 0);
603 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
604 legalTypes
, 3, BGRA_OR_4
,
605 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
610 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
613 GET_CURRENT_CONTEXT(ctx
);
614 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
615 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
616 : (SHORT_BIT
| INT_BIT
|
617 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
618 UNSIGNED_INT_2_10_10_10_REV_BIT
|
619 INT_2_10_10_10_REV_BIT
);
620 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
621 const GLuint unit
= ctx
->Array
.ActiveTexture
;
623 FLUSH_VERTICES(ctx
, 0);
625 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
626 legalTypes
, sizeMin
, 4,
627 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
633 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
635 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
636 /* this is the same type that glEdgeFlag uses */
637 const GLboolean integer
= GL_FALSE
;
638 GET_CURRENT_CONTEXT(ctx
);
640 FLUSH_VERTICES(ctx
, 0);
642 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
644 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
649 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
651 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
652 GET_CURRENT_CONTEXT(ctx
);
654 FLUSH_VERTICES(ctx
, 0);
656 if (ctx
->API
!= API_OPENGLES
) {
657 _mesa_error(ctx
, GL_INVALID_OPERATION
,
658 "glPointSizePointer(ES 1.x only)");
662 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
664 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
669 * Set a generic vertex attribute array.
670 * Note that these arrays DO NOT alias the conventional GL vertex arrays
671 * (position, normal, color, fog, texcoord, etc).
674 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
675 GLboolean normalized
,
676 GLsizei stride
, const GLvoid
*ptr
)
678 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
679 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
680 INT_BIT
| UNSIGNED_INT_BIT
|
681 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
682 FIXED_ES_BIT
| FIXED_GL_BIT
|
683 UNSIGNED_INT_2_10_10_10_REV_BIT
|
684 INT_2_10_10_10_REV_BIT
|
685 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
686 GET_CURRENT_CONTEXT(ctx
);
688 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
689 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
693 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
694 legalTypes
, 1, BGRA_OR_4
,
695 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
700 * GL_EXT_gpu_shader4 / GL 3.0.
701 * Set an integer-valued vertex attribute array.
702 * Note that these arrays DO NOT alias the conventional GL vertex arrays
703 * (position, normal, color, fog, texcoord, etc).
706 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
707 GLsizei stride
, const GLvoid
*ptr
)
709 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
710 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
711 INT_BIT
| UNSIGNED_INT_BIT
);
712 const GLboolean normalized
= GL_FALSE
;
713 const GLboolean integer
= GL_TRUE
;
714 GET_CURRENT_CONTEXT(ctx
);
716 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
717 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
721 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
723 size
, type
, stride
, normalized
, integer
, GL_FALSE
, ptr
);
727 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
728 GLsizei stride
, const GLvoid
*ptr
)
730 GET_CURRENT_CONTEXT(ctx
);
731 const GLbitfield legalTypes
= (DOUBLE_BIT
);
732 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
733 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
737 update_array(ctx
, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index
),
739 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_TRUE
, ptr
);
744 enable_vertex_array_attrib(struct gl_context
*ctx
,
745 struct gl_vertex_array_object
*vao
,
749 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
750 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
754 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
756 if (!vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
757 /* was disabled, now being enabled */
758 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
759 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
760 vao
->_Enabled
|= VERT_BIT_GENERIC(index
);
761 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
767 _mesa_EnableVertexAttribArray(GLuint index
)
769 GET_CURRENT_CONTEXT(ctx
);
770 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
771 "glEnableVertexAttribArray");
776 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
778 GET_CURRENT_CONTEXT(ctx
);
779 struct gl_vertex_array_object
*vao
;
781 /* The ARB_direct_state_access specification says:
783 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
784 * and DisableVertexArrayAttrib if <vaobj> is not
785 * [compatibility profile: zero or] the name of an existing vertex
788 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
792 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
797 disable_vertex_array_attrib(struct gl_context
*ctx
,
798 struct gl_vertex_array_object
*vao
,
802 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
803 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
807 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
809 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
810 /* was enabled, now being disabled */
811 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
812 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
813 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
814 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
820 _mesa_DisableVertexAttribArray(GLuint index
)
822 GET_CURRENT_CONTEXT(ctx
);
823 disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
824 "glDisableVertexAttribArray");
829 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
831 GET_CURRENT_CONTEXT(ctx
);
832 struct gl_vertex_array_object
*vao
;
834 /* The ARB_direct_state_access specification says:
836 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
837 * and DisableVertexArrayAttrib if <vaobj> is not
838 * [compatibility profile: zero or] the name of an existing vertex
841 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
845 disable_vertex_array_attrib(ctx
, vao
, index
, "glDisableVertexArrayAttrib");
850 * Return info for a vertex attribute array (no alias with legacy
851 * vertex attributes (pos, normal, color, etc)). This function does
852 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
855 get_vertex_array_attrib(struct gl_context
*ctx
,
856 const struct gl_vertex_array_object
*vao
,
857 GLuint index
, GLenum pname
,
860 const struct gl_vertex_attrib_array
*array
;
862 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
863 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
867 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
869 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
872 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
873 return array
->Enabled
;
874 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
875 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
876 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
877 return array
->Stride
;
878 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
880 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
881 return array
->Normalized
;
882 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
883 return vao
->VertexBinding
[array
->VertexBinding
].BufferObj
->Name
;
884 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
885 if ((_mesa_is_desktop_gl(ctx
)
886 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
887 || _mesa_is_gles3(ctx
)) {
888 return array
->Integer
;
891 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
892 if (_mesa_is_desktop_gl(ctx
)) {
893 return array
->Doubles
;
896 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
897 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
898 || _mesa_is_gles3(ctx
)) {
899 return vao
->VertexBinding
[array
->VertexBinding
].InstanceDivisor
;
902 case GL_VERTEX_ATTRIB_BINDING
:
903 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
904 return array
->VertexBinding
- VERT_ATTRIB_GENERIC0
;
907 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
908 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
909 return array
->RelativeOffset
;
917 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
922 static const GLfloat
*
923 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
926 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
927 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
931 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
932 _mesa_error(ctx
, GL_INVALID_VALUE
,
933 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
937 assert(VERT_ATTRIB_GENERIC(index
) <
938 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
940 FLUSH_CURRENT(ctx
, 0);
941 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
945 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
947 GET_CURRENT_CONTEXT(ctx
);
949 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
950 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
956 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
958 "glGetVertexAttribfv");
964 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
966 GET_CURRENT_CONTEXT(ctx
);
968 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
969 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
971 params
[0] = (GLdouble
) v
[0];
972 params
[1] = (GLdouble
) v
[1];
973 params
[2] = (GLdouble
) v
[2];
974 params
[3] = (GLdouble
) v
[3];
978 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
980 "glGetVertexAttribdv");
985 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
987 GET_CURRENT_CONTEXT(ctx
);
989 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
991 (const GLdouble
*)get_current_attrib(ctx
, index
,
992 "glGetVertexAttribLdv");
1001 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1003 "glGetVertexAttribLdv");
1008 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
1010 GET_CURRENT_CONTEXT(ctx
);
1012 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1013 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1015 /* XXX should floats in[0,1] be scaled to full int range? */
1016 params
[0] = (GLint
) v
[0];
1017 params
[1] = (GLint
) v
[1];
1018 params
[2] = (GLint
) v
[2];
1019 params
[3] = (GLint
) v
[3];
1023 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1025 "glGetVertexAttribiv");
1032 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1034 GET_CURRENT_CONTEXT(ctx
);
1036 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1037 const GLint
*v
= (const GLint
*)
1038 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1044 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1046 "glGetVertexAttribIiv");
1053 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1055 GET_CURRENT_CONTEXT(ctx
);
1057 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1058 const GLuint
*v
= (const GLuint
*)
1059 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1065 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1067 "glGetVertexAttribIuiv");
1073 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1075 GET_CURRENT_CONTEXT(ctx
);
1077 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1078 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1082 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1083 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1087 assert(VERT_ATTRIB_GENERIC(index
) <
1088 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1090 *pointer
= (GLvoid
*)
1091 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1095 /** ARB_direct_state_access */
1097 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
1098 GLenum pname
, GLint
*params
)
1100 GET_CURRENT_CONTEXT(ctx
);
1101 struct gl_vertex_array_object
*vao
;
1103 /* The ARB_direct_state_access specification says:
1105 * "An INVALID_OPERATION error is generated if <vaobj> is not
1106 * [compatibility profile: zero or] the name of an existing
1107 * vertex array object."
1109 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexediv");
1113 /* The ARB_direct_state_access specification says:
1115 * "For GetVertexArrayIndexediv, <pname> must be one of
1116 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1117 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1118 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1119 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1120 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1124 * "Add GetVertexArrayIndexediv in 'Get Command' for
1125 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1126 * VERTEX_ATTRIB_BINDING,
1127 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1128 * VERTEX_BINDING_OFFSET, and
1129 * VERTEX_BINDING_STRIDE states"
1131 * The only parameter name common to both lists is
1132 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1133 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1134 * pretty clear however that the intent is that it should be possible
1135 * to query all vertex attrib and binding states that can be set with
1139 case GL_VERTEX_BINDING_OFFSET
:
1140 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1142 case GL_VERTEX_BINDING_STRIDE
:
1143 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
1145 case GL_VERTEX_BINDING_DIVISOR
:
1146 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
1148 case GL_VERTEX_BINDING_BUFFER
:
1149 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
1152 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
1153 "glGetVertexArrayIndexediv");
1160 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
1161 GLenum pname
, GLint64
*params
)
1163 GET_CURRENT_CONTEXT(ctx
);
1164 struct gl_vertex_array_object
*vao
;
1166 /* The ARB_direct_state_access specification says:
1168 * "An INVALID_OPERATION error is generated if <vaobj> is not
1169 * [compatibility profile: zero or] the name of an existing
1170 * vertex array object."
1172 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexed64iv");
1176 /* The ARB_direct_state_access specification says:
1178 * "For GetVertexArrayIndexed64iv, <pname> must be
1179 * VERTEX_BINDING_OFFSET."
1183 * "An INVALID_ENUM error is generated if <pname> is not one of
1184 * the valid values listed above for the corresponding command."
1186 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
1187 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
1188 "pname != GL_VERTEX_BINDING_OFFSET)");
1192 /* The ARB_direct_state_access specification says:
1194 * "An INVALID_VALUE error is generated if <index> is greater than
1195 * or equal to the value of MAX_VERTEX_ATTRIBS."
1197 * Since the index refers to a buffer binding in this case, the intended
1198 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1199 * required to be the same, so in practice this doesn't matter.
1201 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
1202 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
1203 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1204 index
, ctx
->Const
.MaxVertexAttribBindings
);
1208 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1213 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1214 GLsizei count
, const GLvoid
*ptr
)
1217 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1222 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1226 _mesa_NormalPointer(type
, stride
, ptr
);
1231 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1235 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1240 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1244 _mesa_IndexPointer(type
, stride
, ptr
);
1249 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1250 GLsizei count
, const GLvoid
*ptr
)
1253 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1258 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1261 _mesa_EdgeFlagPointer(stride
, ptr
);
1266 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1268 GET_CURRENT_CONTEXT(ctx
);
1269 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1270 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1271 GLenum ctype
= 0; /* color type */
1272 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1273 const GLint toffset
= 0; /* always zero */
1274 GLint defstride
; /* default stride */
1277 FLUSH_VERTICES(ctx
, 0);
1279 f
= sizeof(GLfloat
);
1280 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1283 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1289 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1290 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1295 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1296 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1301 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1302 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1303 ctype
= GL_UNSIGNED_BYTE
;
1306 defstride
= c
+ 2*f
;
1309 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1310 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1311 ctype
= GL_UNSIGNED_BYTE
;
1314 defstride
= c
+ 3*f
;
1317 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1318 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1325 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1326 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1331 case GL_C4F_N3F_V3F
:
1332 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1333 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1341 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1342 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1347 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1348 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1352 case GL_T2F_C4UB_V3F
:
1353 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1354 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1355 ctype
= GL_UNSIGNED_BYTE
;
1360 case GL_T2F_C3F_V3F
:
1361 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1362 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1368 case GL_T2F_N3F_V3F
:
1369 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1370 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1375 case GL_T2F_C4F_N3F_V3F
:
1376 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1377 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1384 case GL_T4F_C4F_N3F_V4F
:
1385 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1386 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1394 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1402 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1403 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1404 /* XXX also disable secondary color and generic arrays? */
1408 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1409 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1410 (GLubyte
*) pointer
+ toffset
);
1413 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1418 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1419 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1420 (GLubyte
*) pointer
+ coffset
);
1423 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1429 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1430 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1433 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1437 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1438 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1439 (GLubyte
*) pointer
+ voffset
);
1444 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1446 GET_CURRENT_CONTEXT(ctx
);
1448 FLUSH_VERTICES(ctx
, 0);
1450 if (MESA_VERBOSE
& VERBOSE_API
)
1451 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1454 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1458 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1461 if (ctx
->Array
.LockCount
!= 0) {
1462 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1466 ctx
->Array
.LockFirst
= first
;
1467 ctx
->Array
.LockCount
= count
;
1469 ctx
->NewState
|= _NEW_ARRAY
;
1474 _mesa_UnlockArraysEXT( void )
1476 GET_CURRENT_CONTEXT(ctx
);
1478 FLUSH_VERTICES(ctx
, 0);
1480 if (MESA_VERBOSE
& VERBOSE_API
)
1481 _mesa_debug(ctx
, "glUnlockArrays\n");
1483 if (ctx
->Array
.LockCount
== 0) {
1484 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1488 ctx
->Array
.LockFirst
= 0;
1489 ctx
->Array
.LockCount
= 0;
1490 ctx
->NewState
|= _NEW_ARRAY
;
1494 /* GL_EXT_multi_draw_arrays */
1496 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1497 const GLsizei
*count
, GLsizei primcount
)
1499 GET_CURRENT_CONTEXT(ctx
);
1502 FLUSH_VERTICES(ctx
, 0);
1504 for (i
= 0; i
< primcount
; i
++) {
1506 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1512 /* GL_IBM_multimode_draw_arrays */
1514 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1515 const GLsizei
* count
,
1516 GLsizei primcount
, GLint modestride
)
1518 GET_CURRENT_CONTEXT(ctx
);
1521 FLUSH_VERTICES(ctx
, 0);
1523 for ( i
= 0 ; i
< primcount
; i
++ ) {
1524 if ( count
[i
] > 0 ) {
1525 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1526 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1532 /* GL_IBM_multimode_draw_arrays */
1534 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1535 GLenum type
, const GLvoid
* const * indices
,
1536 GLsizei primcount
, GLint modestride
)
1538 GET_CURRENT_CONTEXT(ctx
);
1541 FLUSH_VERTICES(ctx
, 0);
1543 /* XXX not sure about ARB_vertex_buffer_object handling here */
1545 for ( i
= 0 ; i
< primcount
; i
++ ) {
1546 if ( count
[i
] > 0 ) {
1547 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1548 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1556 * GL_NV_primitive_restart and GL 3.1
1559 _mesa_PrimitiveRestartIndex(GLuint index
)
1561 GET_CURRENT_CONTEXT(ctx
);
1563 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1564 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1568 if (ctx
->Array
.RestartIndex
!= index
) {
1569 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1570 ctx
->Array
.RestartIndex
= index
;
1576 * See GL_ARB_instanced_arrays.
1577 * Note that the instance divisor only applies to generic arrays, not
1578 * the legacy vertex arrays.
1581 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1583 GET_CURRENT_CONTEXT(ctx
);
1585 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1586 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1588 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1589 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1593 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1594 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1599 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
1601 /* The ARB_vertex_attrib_binding spec says:
1605 * void VertexAttribDivisor(uint index, uint divisor);
1607 * is equivalent to (assuming no errors are generated):
1609 * VertexAttribBinding(index, index);
1610 * VertexBindingDivisor(index, divisor);"
1612 vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
1613 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
1618 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1620 /* From the OpenGL 4.3 core specification, page 302:
1621 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1622 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1625 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1627 case GL_UNSIGNED_BYTE
:
1629 case GL_UNSIGNED_SHORT
:
1631 case GL_UNSIGNED_INT
:
1634 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1638 return ctx
->Array
.RestartIndex
;
1643 * GL_ARB_vertex_attrib_binding
1646 vertex_array_vertex_buffer(struct gl_context
*ctx
,
1647 struct gl_vertex_array_object
*vao
,
1648 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1649 GLsizei stride
, const char *func
)
1651 struct gl_buffer_object
*vbo
;
1653 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1655 /* The ARB_vertex_attrib_binding spec says:
1657 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1658 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1660 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1661 _mesa_error(ctx
, GL_INVALID_VALUE
,
1662 "%s(bindingindex=%u > "
1663 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1664 func
, bindingIndex
);
1668 /* The ARB_vertex_attrib_binding spec says:
1670 * "The error INVALID_VALUE is generated if <stride> or <offset>
1674 _mesa_error(ctx
, GL_INVALID_VALUE
,
1675 "%s(offset=%" PRId64
" < 0)",
1676 func
, (int64_t) offset
);
1681 _mesa_error(ctx
, GL_INVALID_VALUE
,
1682 "%s(stride=%d < 0)", func
, stride
);
1686 if (((ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
1687 stride
> ctx
->Const
.MaxVertexAttribStride
) {
1688 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
1689 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
1694 vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1695 vbo
= vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1696 } else if (buffer
!= 0) {
1697 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1699 /* From the GL_ARB_vertex_attrib_array spec:
1701 * "[Core profile only:]
1702 * An INVALID_OPERATION error is generated if buffer is not zero or a
1703 * name returned from a previous call to GenBuffers, or if such a name
1704 * has since been deleted with DeleteBuffers.
1706 * Otherwise, we fall back to the same compat profile behavior as other
1707 * object references (automatically gen it).
1709 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
1712 /* The ARB_vertex_attrib_binding spec says:
1714 * "If <buffer> is zero, any buffer object attached to this
1715 * bindpoint is detached."
1717 vbo
= ctx
->Shared
->NullBufferObj
;
1720 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
1721 vbo
, offset
, stride
);
1726 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1729 GET_CURRENT_CONTEXT(ctx
);
1731 /* The ARB_vertex_attrib_binding spec says:
1733 * "An INVALID_OPERATION error is generated if no vertex array object
1736 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
1737 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1738 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1739 "glBindVertexBuffer(No array object bound)");
1743 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
1744 buffer
, offset
, stride
, "glBindVertexBuffer");
1749 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
1750 GLintptr offset
, GLsizei stride
)
1752 GET_CURRENT_CONTEXT(ctx
);
1753 struct gl_vertex_array_object
*vao
;
1755 /* The ARB_direct_state_access specification says:
1757 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1758 * if <vaobj> is not [compatibility profile: zero or] the name of an
1759 * existing vertex array object."
1761 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
1765 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
,
1766 buffer
, offset
, stride
,
1767 "glVertexArrayVertexBuffer");
1772 vertex_array_vertex_buffers(struct gl_context
*ctx
,
1773 struct gl_vertex_array_object
*vao
,
1774 GLuint first
, GLsizei count
, const GLuint
*buffers
,
1775 const GLintptr
*offsets
, const GLsizei
*strides
,
1780 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1782 /* The ARB_multi_bind spec says:
1784 * "An INVALID_OPERATION error is generated if <first> + <count>
1785 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1787 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1788 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1789 "%s(first=%u + count=%d > the value of "
1790 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1791 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1797 * The ARB_multi_bind spec says:
1799 * "If <buffers> is NULL, each affected vertex buffer binding point
1800 * from <first> through <first>+<count>-1 will be reset to have no
1801 * bound buffer object. In this case, the offsets and strides
1802 * associated with the binding points are set to default values,
1803 * ignoring <offsets> and <strides>."
1805 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1807 for (i
= 0; i
< count
; i
++)
1808 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1814 /* Note that the error semantics for multi-bind commands differ from
1815 * those of other GL commands.
1817 * The Issues section in the ARB_multi_bind spec says:
1819 * "(11) Typically, OpenGL specifies that if an error is generated by
1820 * a command, that command has no effect. This is somewhat
1821 * unfortunate for multi-bind commands, because it would require
1822 * a first pass to scan the entire list of bound objects for
1823 * errors and then a second pass to actually perform the
1824 * bindings. Should we have different error semantics?
1826 * RESOLVED: Yes. In this specification, when the parameters for
1827 * one of the <count> binding points are invalid, that binding
1828 * point is not updated and an error will be generated. However,
1829 * other binding points in the same command will be updated if
1830 * their parameters are valid and no other error occurs."
1833 _mesa_begin_bufferobj_lookups(ctx
);
1835 for (i
= 0; i
< count
; i
++) {
1836 struct gl_buffer_object
*vbo
;
1838 /* The ARB_multi_bind spec says:
1840 * "An INVALID_VALUE error is generated if any value in
1841 * <offsets> or <strides> is negative (per binding)."
1843 if (offsets
[i
] < 0) {
1844 _mesa_error(ctx
, GL_INVALID_VALUE
,
1845 "%s(offsets[%u]=%" PRId64
" < 0)",
1846 func
, i
, (int64_t) offsets
[i
]);
1850 if (strides
[i
] < 0) {
1851 _mesa_error(ctx
, GL_INVALID_VALUE
,
1852 "%s(strides[%u]=%d < 0)",
1853 func
, i
, strides
[i
]);
1857 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1858 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
1859 _mesa_error(ctx
, GL_INVALID_VALUE
,
1860 "%s(strides[%u]=%d > "
1861 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
1866 struct gl_vertex_buffer_binding
*binding
=
1867 &vao
->VertexBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1869 if (buffers
[i
] == binding
->BufferObj
->Name
)
1870 vbo
= binding
->BufferObj
;
1872 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
1877 vbo
= ctx
->Shared
->NullBufferObj
;
1880 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1881 vbo
, offsets
[i
], strides
[i
]);
1884 _mesa_end_bufferobj_lookups(ctx
);
1889 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1890 const GLintptr
*offsets
, const GLsizei
*strides
)
1892 GET_CURRENT_CONTEXT(ctx
);
1894 /* The ARB_vertex_attrib_binding spec says:
1896 * "An INVALID_OPERATION error is generated if no
1897 * vertex array object is bound."
1899 if (ctx
->API
== API_OPENGL_CORE
&&
1900 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1901 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1902 "glBindVertexBuffers(No array object bound)");
1906 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
1907 buffers
, offsets
, strides
,
1908 "glBindVertexBuffers");
1913 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
1914 const GLuint
*buffers
,
1915 const GLintptr
*offsets
, const GLsizei
*strides
)
1917 GET_CURRENT_CONTEXT(ctx
);
1918 struct gl_vertex_array_object
*vao
;
1920 /* The ARB_direct_state_access specification says:
1922 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1923 * if <vaobj> is not [compatibility profile: zero or] the name of an
1924 * existing vertex array object."
1926 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
1930 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
1931 buffers
, offsets
, strides
,
1932 "glVertexArrayVertexBuffers");
1937 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
1938 GLboolean normalized
, GLboolean integer
,
1939 GLboolean doubles
, GLbitfield legalTypes
,
1940 GLsizei maxSize
, GLuint relativeOffset
,
1943 GET_CURRENT_CONTEXT(ctx
);
1944 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1946 /* The ARB_vertex_attrib_binding spec says:
1948 * "An INVALID_OPERATION error is generated under any of the following
1950 * - if no vertex array object is currently bound (see section 2.10);
1953 * This error condition only applies to VertexAttribFormat and
1954 * VertexAttribIFormat in the extension spec, but we assume that this
1955 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
1956 * to all three functions.
1958 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
1959 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1960 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1961 "%s(No array object bound)", func
);
1965 /* The ARB_vertex_attrib_binding spec says:
1967 * "The error INVALID_VALUE is generated if index is greater than or equal
1968 * to the value of MAX_VERTEX_ATTRIBS."
1970 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1971 _mesa_error(ctx
, GL_INVALID_VALUE
,
1972 "%s(attribindex=%u > "
1973 "GL_MAX_VERTEX_ATTRIBS)",
1978 FLUSH_VERTICES(ctx
, 0);
1980 update_array_format(ctx
, func
, ctx
->Array
.VAO
,
1981 VERT_ATTRIB_GENERIC(attribIndex
),
1982 legalTypes
, 1, maxSize
, size
, type
,
1983 normalized
, integer
, doubles
, relativeOffset
);
1988 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1989 GLboolean normalized
, GLuint relativeOffset
)
1991 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
1992 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
1993 BGRA_OR_4
, relativeOffset
,
1994 "glVertexAttribFormat");
1999 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2000 GLuint relativeOffset
)
2002 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
2003 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
2004 relativeOffset
, "glVertexAttribIFormat");
2009 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2010 GLuint relativeOffset
)
2012 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
2013 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
2014 relativeOffset
, "glVertexAttribLFormat");
2019 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2020 GLenum type
, GLboolean normalized
,
2021 GLboolean integer
, GLboolean doubles
,
2022 GLbitfield legalTypes
, GLsizei maxSize
,
2023 GLuint relativeOffset
, const char *func
)
2025 GET_CURRENT_CONTEXT(ctx
);
2026 struct gl_vertex_array_object
*vao
;
2028 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2030 /* The ARB_direct_state_access spec says:
2032 * "An INVALID_OPERATION error is generated by VertexArrayAttrib*Format
2033 * if <vaobj> is not [compatibility profile: zero or] the name of an
2034 * existing vertex array object."
2036 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
2040 /* The ARB_vertex_attrib_binding spec says:
2042 * "The error INVALID_VALUE is generated if index is greater than or equal
2043 * to the value of MAX_VERTEX_ATTRIBS."
2045 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2046 _mesa_error(ctx
, GL_INVALID_VALUE
,
2047 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2052 FLUSH_VERTICES(ctx
, 0);
2054 update_array_format(ctx
, func
, vao
,
2055 VERT_ATTRIB_GENERIC(attribIndex
),
2056 legalTypes
, 1, maxSize
, size
, type
, normalized
,
2057 integer
, doubles
, relativeOffset
);
2062 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2063 GLenum type
, GLboolean normalized
,
2064 GLuint relativeOffset
)
2066 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
2067 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2068 BGRA_OR_4
, relativeOffset
,
2069 "glVertexArrayAttribFormat");
2074 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
2075 GLint size
, GLenum type
,
2076 GLuint relativeOffset
)
2078 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2079 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
2081 "glVertexArrayAttribIFormat");
2086 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
2087 GLint size
, GLenum type
,
2088 GLuint relativeOffset
)
2090 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2091 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
2093 "glVertexArrayAttribLFormat");
2098 vertex_array_attrib_binding(struct gl_context
*ctx
,
2099 struct gl_vertex_array_object
*vao
,
2100 GLuint attribIndex
, GLuint bindingIndex
,
2103 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2105 /* The ARB_vertex_attrib_binding spec says:
2107 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2108 * <bindingindex> must be less than the value of
2109 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2112 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2113 _mesa_error(ctx
, GL_INVALID_VALUE
,
2114 "%s(attribindex=%u >= "
2115 "GL_MAX_VERTEX_ATTRIBS)",
2120 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2121 _mesa_error(ctx
, GL_INVALID_VALUE
,
2122 "%s(bindingindex=%u >= "
2123 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2124 func
, bindingIndex
);
2128 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
2130 vertex_attrib_binding(ctx
, vao
,
2131 VERT_ATTRIB_GENERIC(attribIndex
),
2132 VERT_ATTRIB_GENERIC(bindingIndex
));
2137 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2139 GET_CURRENT_CONTEXT(ctx
);
2141 /* The ARB_vertex_attrib_binding spec says:
2143 * "An INVALID_OPERATION error is generated if no vertex array object
2146 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2147 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2148 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2149 "glVertexAttribBinding(No array object bound)");
2153 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2154 attribIndex
, bindingIndex
,
2155 "glVertexAttribBinding");
2160 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2162 GET_CURRENT_CONTEXT(ctx
);
2163 struct gl_vertex_array_object
*vao
;
2165 /* The ARB_direct_state_access specification says:
2167 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2168 * if <vaobj> is not [compatibility profile: zero or] the name of an
2169 * existing vertex array object."
2171 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2175 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2176 "glVertexArrayAttribBinding");
2181 vertex_array_binding_divisor(struct gl_context
*ctx
,
2182 struct gl_vertex_array_object
*vao
,
2183 GLuint bindingIndex
, GLuint divisor
,
2186 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2188 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2189 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
2193 /* The ARB_vertex_attrib_binding spec says:
2195 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2196 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2198 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2199 _mesa_error(ctx
, GL_INVALID_VALUE
,
2200 "%s(bindingindex=%u > "
2201 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2202 func
, bindingIndex
);
2206 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2211 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2213 GET_CURRENT_CONTEXT(ctx
);
2215 /* The ARB_vertex_attrib_binding spec says:
2217 * "An INVALID_OPERATION error is generated if no vertex array object
2220 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2221 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2222 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2223 "glVertexBindingDivisor(No array object bound)");
2227 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
2228 bindingIndex
, divisor
,
2229 "glVertexBindingDivisor");
2234 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
2237 struct gl_vertex_array_object
*vao
;
2238 GET_CURRENT_CONTEXT(ctx
);
2240 /* The ARB_direct_state_access specification says:
2242 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2243 * if <vaobj> is not [compatibility profile: zero or] the name of an
2244 * existing vertex array object."
2246 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayBindingDivisor");
2250 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
2251 "glVertexArrayBindingDivisor");
2256 * Copy one client vertex array to another.
2259 _mesa_copy_client_array(struct gl_context
*ctx
,
2260 struct gl_client_array
*dst
,
2261 struct gl_client_array
*src
)
2263 dst
->Size
= src
->Size
;
2264 dst
->Type
= src
->Type
;
2265 dst
->Format
= src
->Format
;
2266 dst
->Stride
= src
->Stride
;
2267 dst
->StrideB
= src
->StrideB
;
2268 dst
->Ptr
= src
->Ptr
;
2269 dst
->Enabled
= src
->Enabled
;
2270 dst
->Normalized
= src
->Normalized
;
2271 dst
->Integer
= src
->Integer
;
2272 dst
->Doubles
= src
->Doubles
;
2273 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2274 dst
->_ElementSize
= src
->_ElementSize
;
2275 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2279 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2280 struct gl_vertex_attrib_array
*dst
,
2281 const struct gl_vertex_attrib_array
*src
)
2283 dst
->Size
= src
->Size
;
2284 dst
->Type
= src
->Type
;
2285 dst
->Format
= src
->Format
;
2286 dst
->VertexBinding
= src
->VertexBinding
;
2287 dst
->RelativeOffset
= src
->RelativeOffset
;
2288 dst
->Format
= src
->Format
;
2289 dst
->Integer
= src
->Integer
;
2290 dst
->Doubles
= src
->Doubles
;
2291 dst
->Normalized
= src
->Normalized
;
2292 dst
->Ptr
= src
->Ptr
;
2293 dst
->Enabled
= src
->Enabled
;
2294 dst
->_ElementSize
= src
->_ElementSize
;
2298 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2299 struct gl_vertex_buffer_binding
*dst
,
2300 const struct gl_vertex_buffer_binding
*src
)
2302 dst
->Offset
= src
->Offset
;
2303 dst
->Stride
= src
->Stride
;
2304 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2305 dst
->_BoundArrays
= src
->_BoundArrays
;
2307 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2311 * Print vertex array's fields.
2314 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
2317 fprintf(stderr
, " %s[%d]: ", name
, index
);
2319 fprintf(stderr
, " %s: ", name
);
2320 fprintf(stderr
, "Ptr=%p, Type=%s, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
2321 array
->Ptr
, _mesa_enum_to_string(array
->Type
), array
->Size
,
2322 array
->_ElementSize
, array
->StrideB
, array
->BufferObj
->Name
,
2323 (unsigned long) array
->BufferObj
->Size
);
2328 * Print current vertex object/array info. For debug.
2331 _mesa_print_arrays(struct gl_context
*ctx
)
2333 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2336 printf("Array Object %u\n", vao
->Name
);
2337 if (vao
->_VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
2338 print_array("Vertex", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_POS
]);
2339 if (vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
2340 print_array("Normal", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
]);
2341 if (vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
2342 print_array("Color", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
]);
2343 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
2344 if (vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
2345 print_array("TexCoord", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
2346 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
2347 if (vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
2348 print_array("Attrib", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
2353 * Initialize vertex array state for given context.
2356 _mesa_init_varray(struct gl_context
*ctx
)
2358 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
2359 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2360 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2362 ctx
->Array
.Objects
= _mesa_NewHashTable();
2367 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2370 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2372 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2373 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2374 _mesa_delete_vao(ctx
, vao
);
2379 * Free vertex array state for given context.
2382 _mesa_free_varray_data(struct gl_context
*ctx
)
2384 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2385 _mesa_DeleteHashTable(ctx
->Array
.Objects
);