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 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_lookup_enum_by_nr(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_lookup_enum_by_nr(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 bind_vertex_buffer(ctx
, ctx
->Array
.VAO
, attrib
, ctx
->Array
.ArrayBufferObj
,
495 (GLintptr
) ptr
, effectiveStride
);
500 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
502 GET_CURRENT_CONTEXT(ctx
);
503 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
504 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
505 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
506 DOUBLE_BIT
| HALF_BIT
|
507 UNSIGNED_INT_2_10_10_10_REV_BIT
|
508 INT_2_10_10_10_REV_BIT
);
510 FLUSH_VERTICES(ctx
, 0);
512 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
514 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
519 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
521 GET_CURRENT_CONTEXT(ctx
);
522 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
523 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
524 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
525 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
526 UNSIGNED_INT_2_10_10_10_REV_BIT
|
527 INT_2_10_10_10_REV_BIT
);
529 FLUSH_VERTICES(ctx
, 0);
531 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
533 3, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
538 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
540 GET_CURRENT_CONTEXT(ctx
);
541 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
542 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
543 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
544 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
545 INT_BIT
| UNSIGNED_INT_BIT
|
546 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
547 UNSIGNED_INT_2_10_10_10_REV_BIT
|
548 INT_2_10_10_10_REV_BIT
);
549 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
551 FLUSH_VERTICES(ctx
, 0);
553 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
554 legalTypes
, sizeMin
, BGRA_OR_4
,
555 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
560 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
562 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
563 GET_CURRENT_CONTEXT(ctx
);
565 FLUSH_VERTICES(ctx
, 0);
567 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
569 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
574 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
576 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
577 FLOAT_BIT
| DOUBLE_BIT
);
578 GET_CURRENT_CONTEXT(ctx
);
580 FLUSH_VERTICES(ctx
, 0);
582 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
584 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
589 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
590 GLsizei stride
, const GLvoid
*ptr
)
592 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
593 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
594 INT_BIT
| UNSIGNED_INT_BIT
|
595 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
596 UNSIGNED_INT_2_10_10_10_REV_BIT
|
597 INT_2_10_10_10_REV_BIT
);
598 GET_CURRENT_CONTEXT(ctx
);
600 FLUSH_VERTICES(ctx
, 0);
602 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
603 legalTypes
, 3, BGRA_OR_4
,
604 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
609 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
612 GET_CURRENT_CONTEXT(ctx
);
613 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
614 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
615 : (SHORT_BIT
| INT_BIT
|
616 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
617 UNSIGNED_INT_2_10_10_10_REV_BIT
|
618 INT_2_10_10_10_REV_BIT
);
619 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
620 const GLuint unit
= ctx
->Array
.ActiveTexture
;
622 FLUSH_VERTICES(ctx
, 0);
624 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
625 legalTypes
, sizeMin
, 4,
626 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
632 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
634 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
635 /* this is the same type that glEdgeFlag uses */
636 const GLboolean integer
= GL_FALSE
;
637 GET_CURRENT_CONTEXT(ctx
);
639 FLUSH_VERTICES(ctx
, 0);
641 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
643 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
648 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
650 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
651 GET_CURRENT_CONTEXT(ctx
);
653 FLUSH_VERTICES(ctx
, 0);
655 if (ctx
->API
!= API_OPENGLES
) {
656 _mesa_error(ctx
, GL_INVALID_OPERATION
,
657 "glPointSizePointer(ES 1.x only)");
661 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
663 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
668 * Set a generic vertex attribute array.
669 * Note that these arrays DO NOT alias the conventional GL vertex arrays
670 * (position, normal, color, fog, texcoord, etc).
673 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
674 GLboolean normalized
,
675 GLsizei stride
, const GLvoid
*ptr
)
677 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
678 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
679 INT_BIT
| UNSIGNED_INT_BIT
|
680 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
681 FIXED_ES_BIT
| FIXED_GL_BIT
|
682 UNSIGNED_INT_2_10_10_10_REV_BIT
|
683 INT_2_10_10_10_REV_BIT
|
684 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
685 GET_CURRENT_CONTEXT(ctx
);
687 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
688 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
692 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
693 legalTypes
, 1, BGRA_OR_4
,
694 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
699 * GL_EXT_gpu_shader4 / GL 3.0.
700 * Set an integer-valued vertex attribute array.
701 * Note that these arrays DO NOT alias the conventional GL vertex arrays
702 * (position, normal, color, fog, texcoord, etc).
705 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
706 GLsizei stride
, const GLvoid
*ptr
)
708 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
709 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
710 INT_BIT
| UNSIGNED_INT_BIT
);
711 const GLboolean normalized
= GL_FALSE
;
712 const GLboolean integer
= GL_TRUE
;
713 GET_CURRENT_CONTEXT(ctx
);
715 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
716 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
720 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
722 size
, type
, stride
, normalized
, integer
, GL_FALSE
, ptr
);
726 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
727 GLsizei stride
, const GLvoid
*ptr
)
729 GET_CURRENT_CONTEXT(ctx
);
730 const GLbitfield legalTypes
= (DOUBLE_BIT
);
731 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
732 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
736 update_array(ctx
, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index
),
738 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_TRUE
, ptr
);
743 enable_vertex_array_attrib(struct gl_context
*ctx
,
744 struct gl_vertex_array_object
*vao
,
748 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
749 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
753 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
755 if (!vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
756 /* was disabled, now being enabled */
757 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
758 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
759 vao
->_Enabled
|= VERT_BIT_GENERIC(index
);
760 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
766 _mesa_EnableVertexAttribArray(GLuint index
)
768 GET_CURRENT_CONTEXT(ctx
);
769 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
770 "glEnableVertexAttribArray");
775 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
777 GET_CURRENT_CONTEXT(ctx
);
778 struct gl_vertex_array_object
*vao
;
780 /* The ARB_direct_state_access specification says:
782 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
783 * and DisableVertexArrayAttrib if <vaobj> is not
784 * [compatibility profile: zero or] the name of an existing vertex
787 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
791 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
796 disable_vertex_array_attrib(struct gl_context
*ctx
,
797 struct gl_vertex_array_object
*vao
,
801 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
802 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
806 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
808 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
809 /* was enabled, now being disabled */
810 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
811 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
812 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
813 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
819 _mesa_DisableVertexAttribArray(GLuint index
)
821 GET_CURRENT_CONTEXT(ctx
);
822 disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
823 "glDisableVertexAttribArray");
828 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
830 GET_CURRENT_CONTEXT(ctx
);
831 struct gl_vertex_array_object
*vao
;
833 /* The ARB_direct_state_access specification says:
835 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
836 * and DisableVertexArrayAttrib if <vaobj> is not
837 * [compatibility profile: zero or] the name of an existing vertex
840 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
844 disable_vertex_array_attrib(ctx
, vao
, index
, "glDisableVertexArrayAttrib");
849 * Return info for a vertex attribute array (no alias with legacy
850 * vertex attributes (pos, normal, color, etc)). This function does
851 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
854 get_vertex_array_attrib(struct gl_context
*ctx
,
855 const struct gl_vertex_array_object
*vao
,
856 GLuint index
, GLenum pname
,
859 const struct gl_vertex_attrib_array
*array
;
861 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
862 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
866 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
868 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
871 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
872 return array
->Enabled
;
873 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
874 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
875 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
876 return array
->Stride
;
877 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
879 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
880 return array
->Normalized
;
881 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
882 return vao
->VertexBinding
[array
->VertexBinding
].BufferObj
->Name
;
883 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
884 if ((_mesa_is_desktop_gl(ctx
)
885 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
886 || _mesa_is_gles3(ctx
)) {
887 return array
->Integer
;
890 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
891 if (_mesa_is_desktop_gl(ctx
)) {
892 return array
->Doubles
;
895 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
896 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
897 || _mesa_is_gles3(ctx
)) {
898 return vao
->VertexBinding
[array
->VertexBinding
].InstanceDivisor
;
901 case GL_VERTEX_ATTRIB_BINDING
:
902 if (_mesa_is_desktop_gl(ctx
)) {
903 return array
->VertexBinding
- VERT_ATTRIB_GENERIC0
;
906 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
907 if (_mesa_is_desktop_gl(ctx
)) {
908 return array
->RelativeOffset
;
916 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
921 static const GLfloat
*
922 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
925 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
926 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
930 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
931 _mesa_error(ctx
, GL_INVALID_VALUE
,
932 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
936 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
938 FLUSH_CURRENT(ctx
, 0);
939 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
943 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
945 GET_CURRENT_CONTEXT(ctx
);
947 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
948 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
954 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
956 "glGetVertexAttribfv");
962 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
964 GET_CURRENT_CONTEXT(ctx
);
966 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
967 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
969 params
[0] = (GLdouble
) v
[0];
970 params
[1] = (GLdouble
) v
[1];
971 params
[2] = (GLdouble
) v
[2];
972 params
[3] = (GLdouble
) v
[3];
976 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
978 "glGetVertexAttribdv");
983 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
985 GET_CURRENT_CONTEXT(ctx
);
987 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
988 const GLdouble
*v
= (const GLdouble
*)get_current_attrib(ctx
, index
, "glGetVertexAttribLdv");
997 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
999 "glGetVertexAttribLdv");
1004 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
1006 GET_CURRENT_CONTEXT(ctx
);
1008 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1009 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1011 /* XXX should floats in[0,1] be scaled to full int range? */
1012 params
[0] = (GLint
) v
[0];
1013 params
[1] = (GLint
) v
[1];
1014 params
[2] = (GLint
) v
[2];
1015 params
[3] = (GLint
) v
[3];
1019 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1021 "glGetVertexAttribiv");
1028 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1030 GET_CURRENT_CONTEXT(ctx
);
1032 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1033 const GLint
*v
= (const GLint
*)
1034 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1040 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1042 "glGetVertexAttribIiv");
1049 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1051 GET_CURRENT_CONTEXT(ctx
);
1053 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1054 const GLuint
*v
= (const GLuint
*)
1055 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1061 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1063 "glGetVertexAttribIuiv");
1069 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1071 GET_CURRENT_CONTEXT(ctx
);
1073 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1074 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1078 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1079 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1083 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1085 *pointer
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1090 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1091 GLsizei count
, const GLvoid
*ptr
)
1094 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1099 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1103 _mesa_NormalPointer(type
, stride
, ptr
);
1108 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1112 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1117 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1121 _mesa_IndexPointer(type
, stride
, ptr
);
1126 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1127 GLsizei count
, const GLvoid
*ptr
)
1130 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1135 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1138 _mesa_EdgeFlagPointer(stride
, ptr
);
1143 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1145 GET_CURRENT_CONTEXT(ctx
);
1146 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1147 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1148 GLenum ctype
= 0; /* color type */
1149 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1150 const GLint toffset
= 0; /* always zero */
1151 GLint defstride
; /* default stride */
1154 FLUSH_VERTICES(ctx
, 0);
1156 f
= sizeof(GLfloat
);
1157 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1160 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1166 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1167 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1172 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1173 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1178 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1179 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1180 ctype
= GL_UNSIGNED_BYTE
;
1183 defstride
= c
+ 2*f
;
1186 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1187 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1188 ctype
= GL_UNSIGNED_BYTE
;
1191 defstride
= c
+ 3*f
;
1194 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1195 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1202 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1203 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1208 case GL_C4F_N3F_V3F
:
1209 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1210 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1218 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1219 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1224 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1225 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1229 case GL_T2F_C4UB_V3F
:
1230 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1231 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1232 ctype
= GL_UNSIGNED_BYTE
;
1237 case GL_T2F_C3F_V3F
:
1238 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1239 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1245 case GL_T2F_N3F_V3F
:
1246 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1247 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1252 case GL_T2F_C4F_N3F_V3F
:
1253 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1254 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1261 case GL_T4F_C4F_N3F_V4F
:
1262 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1263 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1271 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1279 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1280 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1281 /* XXX also disable secondary color and generic arrays? */
1285 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1286 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1287 (GLubyte
*) pointer
+ toffset
);
1290 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1295 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1296 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1297 (GLubyte
*) pointer
+ coffset
);
1300 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1306 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1307 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1310 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1314 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1315 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1316 (GLubyte
*) pointer
+ voffset
);
1321 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1323 GET_CURRENT_CONTEXT(ctx
);
1325 FLUSH_VERTICES(ctx
, 0);
1327 if (MESA_VERBOSE
& VERBOSE_API
)
1328 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1331 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1335 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1338 if (ctx
->Array
.LockCount
!= 0) {
1339 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1343 ctx
->Array
.LockFirst
= first
;
1344 ctx
->Array
.LockCount
= count
;
1346 ctx
->NewState
|= _NEW_ARRAY
;
1351 _mesa_UnlockArraysEXT( void )
1353 GET_CURRENT_CONTEXT(ctx
);
1355 FLUSH_VERTICES(ctx
, 0);
1357 if (MESA_VERBOSE
& VERBOSE_API
)
1358 _mesa_debug(ctx
, "glUnlockArrays\n");
1360 if (ctx
->Array
.LockCount
== 0) {
1361 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1365 ctx
->Array
.LockFirst
= 0;
1366 ctx
->Array
.LockCount
= 0;
1367 ctx
->NewState
|= _NEW_ARRAY
;
1371 /* GL_EXT_multi_draw_arrays */
1373 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1374 const GLsizei
*count
, GLsizei primcount
)
1376 GET_CURRENT_CONTEXT(ctx
);
1379 FLUSH_VERTICES(ctx
, 0);
1381 for (i
= 0; i
< primcount
; i
++) {
1383 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1389 /* GL_IBM_multimode_draw_arrays */
1391 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1392 const GLsizei
* count
,
1393 GLsizei primcount
, GLint modestride
)
1395 GET_CURRENT_CONTEXT(ctx
);
1398 FLUSH_VERTICES(ctx
, 0);
1400 for ( i
= 0 ; i
< primcount
; i
++ ) {
1401 if ( count
[i
] > 0 ) {
1402 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1403 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1409 /* GL_IBM_multimode_draw_arrays */
1411 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1412 GLenum type
, const GLvoid
* const * indices
,
1413 GLsizei primcount
, GLint modestride
)
1415 GET_CURRENT_CONTEXT(ctx
);
1418 FLUSH_VERTICES(ctx
, 0);
1420 /* XXX not sure about ARB_vertex_buffer_object handling here */
1422 for ( i
= 0 ; i
< primcount
; i
++ ) {
1423 if ( count
[i
] > 0 ) {
1424 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1425 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1433 * GL_NV_primitive_restart and GL 3.1
1436 _mesa_PrimitiveRestartIndex(GLuint index
)
1438 GET_CURRENT_CONTEXT(ctx
);
1440 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1441 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1445 if (ctx
->Array
.RestartIndex
!= index
) {
1446 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1447 ctx
->Array
.RestartIndex
= index
;
1453 * See GL_ARB_instanced_arrays.
1454 * Note that the instance divisor only applies to generic arrays, not
1455 * the legacy vertex arrays.
1458 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1460 GET_CURRENT_CONTEXT(ctx
);
1462 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1463 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1465 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1466 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1470 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1471 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1476 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
1478 /* The ARB_vertex_attrib_binding spec says:
1482 * void VertexAttribDivisor(uint index, uint divisor);
1484 * is equivalent to (assuming no errors are generated):
1486 * VertexAttribBinding(index, index);
1487 * VertexBindingDivisor(index, divisor);"
1489 vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
1490 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
1495 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1497 /* From the OpenGL 4.3 core specification, page 302:
1498 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1499 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1502 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1504 case GL_UNSIGNED_BYTE
:
1506 case GL_UNSIGNED_SHORT
:
1508 case GL_UNSIGNED_INT
:
1511 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1515 return ctx
->Array
.RestartIndex
;
1520 * GL_ARB_vertex_attrib_binding
1523 vertex_array_vertex_buffer(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
,
1524 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1525 GLsizei stride
, const char *func
)
1527 struct gl_buffer_object
*vbo
;
1529 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1531 /* The ARB_vertex_attrib_binding spec says:
1533 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1534 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1536 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1537 _mesa_error(ctx
, GL_INVALID_VALUE
,
1538 "%s(bindingindex=%u > "
1539 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1540 func
, bindingIndex
);
1544 /* The ARB_vertex_attrib_binding spec says:
1546 * "The error INVALID_VALUE is generated if <stride> or <offset>
1550 _mesa_error(ctx
, GL_INVALID_VALUE
,
1551 "%s(offset=%" PRId64
" < 0)",
1552 func
, (int64_t) offset
);
1557 _mesa_error(ctx
, GL_INVALID_VALUE
,
1558 "%s(stride=%d < 0)", func
, stride
);
1562 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1563 stride
> ctx
->Const
.MaxVertexAttribStride
) {
1564 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
1565 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
1569 if (buffer
== vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1570 vbo
= vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1571 } else if (buffer
!= 0) {
1572 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1574 /* From the GL_ARB_vertex_attrib_array spec:
1576 * "[Core profile only:]
1577 * An INVALID_OPERATION error is generated if buffer is not zero or a
1578 * name returned from a previous call to GenBuffers, or if such a name
1579 * has since been deleted with DeleteBuffers.
1581 * Otherwise, we fall back to the same compat profile behavior as other
1582 * object references (automatically gen it).
1584 if (!_mesa_handle_bind_buffer_gen(ctx
, GL_ARRAY_BUFFER
, buffer
,
1588 /* The ARB_vertex_attrib_binding spec says:
1590 * "If <buffer> is zero, any buffer object attached to this
1591 * bindpoint is detached."
1593 vbo
= ctx
->Shared
->NullBufferObj
;
1596 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
1597 vbo
, offset
, stride
);
1602 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1605 GET_CURRENT_CONTEXT(ctx
);
1607 /* The ARB_vertex_attrib_binding spec says:
1609 * "An INVALID_OPERATION error is generated if no vertex array object
1612 if (ctx
->API
== API_OPENGL_CORE
&&
1613 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1614 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1615 "glBindVertexBuffer(No array object bound)");
1619 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
1620 buffer
, offset
, stride
, "glBindVertexBuffer");
1625 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
1626 GLintptr offset
, GLsizei stride
)
1628 GET_CURRENT_CONTEXT(ctx
);
1629 struct gl_vertex_array_object
*vao
;
1631 /* The ARB_direct_state_access specification says:
1633 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1634 * if <vaobj> is not [compatibility profile: zero or] the name of an
1635 * existing vertex array object."
1637 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
1641 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
,
1642 buffer
, offset
, stride
,
1643 "glVertexArrayVertexBuffer");
1648 vertex_array_vertex_buffers(struct gl_context
*ctx
,
1649 struct gl_vertex_array_object
*vao
,
1650 GLuint first
, GLsizei count
, const GLuint
*buffers
,
1651 const GLintptr
*offsets
, const GLsizei
*strides
,
1656 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1658 /* The ARB_multi_bind spec says:
1660 * "An INVALID_OPERATION error is generated if <first> + <count>
1661 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1663 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1664 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1665 "%s(first=%u + count=%d > the value of "
1666 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1667 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1673 * The ARB_multi_bind spec says:
1675 * "If <buffers> is NULL, each affected vertex buffer binding point
1676 * from <first> through <first>+<count>-1 will be reset to have no
1677 * bound buffer object. In this case, the offsets and strides
1678 * associated with the binding points are set to default values,
1679 * ignoring <offsets> and <strides>."
1681 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1683 for (i
= 0; i
< count
; i
++)
1684 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1690 /* Note that the error semantics for multi-bind commands differ from
1691 * those of other GL commands.
1693 * The Issues section in the ARB_multi_bind spec says:
1695 * "(11) Typically, OpenGL specifies that if an error is generated by
1696 * a command, that command has no effect. This is somewhat
1697 * unfortunate for multi-bind commands, because it would require
1698 * a first pass to scan the entire list of bound objects for
1699 * errors and then a second pass to actually perform the
1700 * bindings. Should we have different error semantics?
1702 * RESOLVED: Yes. In this specification, when the parameters for
1703 * one of the <count> binding points are invalid, that binding
1704 * point is not updated and an error will be generated. However,
1705 * other binding points in the same command will be updated if
1706 * their parameters are valid and no other error occurs."
1709 _mesa_begin_bufferobj_lookups(ctx
);
1711 for (i
= 0; i
< count
; i
++) {
1712 struct gl_buffer_object
*vbo
;
1714 /* The ARB_multi_bind spec says:
1716 * "An INVALID_VALUE error is generated if any value in
1717 * <offsets> or <strides> is negative (per binding)."
1719 if (offsets
[i
] < 0) {
1720 _mesa_error(ctx
, GL_INVALID_VALUE
,
1721 "%s(offsets[%u]=%" PRId64
" < 0)",
1722 func
, i
, (int64_t) offsets
[i
]);
1726 if (strides
[i
] < 0) {
1727 _mesa_error(ctx
, GL_INVALID_VALUE
,
1728 "%s(strides[%u]=%d < 0)",
1729 func
, i
, strides
[i
]);
1733 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1734 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
1735 _mesa_error(ctx
, GL_INVALID_VALUE
,
1736 "%s(strides[%u]=%d > "
1737 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
1742 struct gl_vertex_buffer_binding
*binding
=
1743 &vao
->VertexBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1745 if (buffers
[i
] == binding
->BufferObj
->Name
)
1746 vbo
= binding
->BufferObj
;
1748 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
1753 vbo
= ctx
->Shared
->NullBufferObj
;
1756 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1757 vbo
, offsets
[i
], strides
[i
]);
1760 _mesa_end_bufferobj_lookups(ctx
);
1765 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1766 const GLintptr
*offsets
, const GLsizei
*strides
)
1768 GET_CURRENT_CONTEXT(ctx
);
1770 /* The ARB_vertex_attrib_binding spec says:
1772 * "An INVALID_OPERATION error is generated if no
1773 * vertex array object is bound."
1775 if (ctx
->API
== API_OPENGL_CORE
&&
1776 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1777 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1778 "glBindVertexBuffers(No array object bound)");
1782 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
1783 buffers
, offsets
, strides
,
1784 "glBindVertexBuffers");
1789 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
1790 const GLuint
*buffers
,
1791 const GLintptr
*offsets
, const GLsizei
*strides
)
1793 GET_CURRENT_CONTEXT(ctx
);
1794 struct gl_vertex_array_object
*vao
;
1796 /* The ARB_direct_state_access specification says:
1798 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1799 * if <vaobj> is not [compatibility profile: zero or] the name of an
1800 * existing vertex array object."
1802 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
1806 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
1807 buffers
, offsets
, strides
,
1808 "glVertexArrayVertexBuffers");
1813 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
1814 GLboolean normalized
, GLboolean integer
,
1815 GLboolean doubles
, GLbitfield legalTypes
,
1816 GLsizei maxSize
, GLuint relativeOffset
,
1819 GET_CURRENT_CONTEXT(ctx
);
1820 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1822 /* The ARB_vertex_attrib_binding spec says:
1824 * "An INVALID_OPERATION error is generated under any of the following
1826 * - if no vertex array object is currently bound (see section 2.10);
1829 * This error condition only applies to VertexAttribFormat and
1830 * VertexAttribIFormat in the extension spec, but we assume that this
1831 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
1832 * to all three functions.
1834 if (ctx
->API
== API_OPENGL_CORE
&&
1835 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1836 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1837 "%s(No array object bound)", func
);
1841 /* The ARB_vertex_attrib_binding spec says:
1843 * "The error INVALID_VALUE is generated if index is greater than or equal
1844 * to the value of MAX_VERTEX_ATTRIBS."
1846 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1847 _mesa_error(ctx
, GL_INVALID_VALUE
,
1848 "%s(attribindex=%u > "
1849 "GL_MAX_VERTEX_ATTRIBS)",
1854 FLUSH_VERTICES(ctx
, 0);
1856 update_array_format(ctx
, func
, ctx
->Array
.VAO
,
1857 VERT_ATTRIB_GENERIC(attribIndex
),
1858 legalTypes
, 1, maxSize
, size
, type
,
1859 normalized
, integer
, doubles
, relativeOffset
);
1864 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1865 GLboolean normalized
, GLuint relativeOffset
)
1867 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
1868 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
1869 BGRA_OR_4
, relativeOffset
,
1870 "glVertexAttribFormat");
1875 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1876 GLuint relativeOffset
)
1878 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
1879 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
1880 relativeOffset
, "glVertexAttribIFormat");
1885 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1886 GLuint relativeOffset
)
1888 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
1889 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
1890 relativeOffset
, "glVertexAttribLFormat");
1895 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
1896 GLenum type
, GLboolean normalized
,
1897 GLboolean integer
, GLboolean doubles
,
1898 GLbitfield legalTypes
, GLsizei maxSize
,
1899 GLuint relativeOffset
, const char *func
)
1901 GET_CURRENT_CONTEXT(ctx
);
1902 struct gl_vertex_array_object
*vao
;
1904 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1906 /* The ARB_direct_state_access spec says:
1908 * "An INVALID_OPERATION error is generated by VertexArrayAttrib*Format
1909 * if <vaobj> is not [compatibility profile: zero or] the name of an
1910 * existing vertex array object."
1912 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
1916 /* The ARB_vertex_attrib_binding spec says:
1918 * "The error INVALID_VALUE is generated if index is greater than or equal
1919 * to the value of MAX_VERTEX_ATTRIBS."
1921 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1922 _mesa_error(ctx
, GL_INVALID_VALUE
,
1923 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
1928 FLUSH_VERTICES(ctx
, 0);
1930 update_array_format(ctx
, func
, vao
,
1931 VERT_ATTRIB_GENERIC(attribIndex
),
1932 legalTypes
, 1, maxSize
, size
, type
, normalized
,
1933 integer
, doubles
, relativeOffset
);
1938 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
1939 GLenum type
, GLboolean normalized
,
1940 GLuint relativeOffset
)
1942 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
1943 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
1944 BGRA_OR_4
, relativeOffset
,
1945 "glVertexArrayAttribFormat");
1950 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
1951 GLint size
, GLenum type
,
1952 GLuint relativeOffset
)
1954 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
1955 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
1957 "glVertexArrayAttribIFormat");
1962 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
1963 GLint size
, GLenum type
,
1964 GLuint relativeOffset
)
1966 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
1967 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
1969 "glVertexArrayAttribLFormat");
1974 vertex_array_attrib_binding(struct gl_context
*ctx
,
1975 struct gl_vertex_array_object
*vao
,
1976 GLuint attribIndex
, GLuint bindingIndex
,
1979 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1981 /* The ARB_vertex_attrib_binding spec says:
1983 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1984 * <bindingindex> must be less than the value of
1985 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1988 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1989 _mesa_error(ctx
, GL_INVALID_VALUE
,
1990 "%s(attribindex=%u >= "
1991 "GL_MAX_VERTEX_ATTRIBS)",
1996 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1997 _mesa_error(ctx
, GL_INVALID_VALUE
,
1998 "%s(bindingindex=%u >= "
1999 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2000 func
, bindingIndex
);
2004 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
2006 vertex_attrib_binding(ctx
, vao
,
2007 VERT_ATTRIB_GENERIC(attribIndex
),
2008 VERT_ATTRIB_GENERIC(bindingIndex
));
2013 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2015 GET_CURRENT_CONTEXT(ctx
);
2017 /* The ARB_vertex_attrib_binding spec says:
2019 * "An INVALID_OPERATION error is generated if no vertex array object
2022 if (ctx
->API
== API_OPENGL_CORE
&&
2023 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2024 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2025 "glVertexAttribBinding(No array object bound)");
2029 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2030 attribIndex
, bindingIndex
,
2031 "glVertexAttribBinding");
2036 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2038 GET_CURRENT_CONTEXT(ctx
);
2039 struct gl_vertex_array_object
*vao
;
2041 /* The ARB_direct_state_access specification says:
2043 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2044 * if <vaobj> is not [compatibility profile: zero or] the name of an
2045 * existing vertex array object."
2047 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2051 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2052 "glVertexArrayAttribBinding");
2057 vertex_array_binding_divisor(struct gl_context
*ctx
,
2058 struct gl_vertex_array_object
*vao
,
2059 GLuint bindingIndex
, GLuint divisor
,
2062 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2064 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2065 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
2069 /* The ARB_vertex_attrib_binding spec says:
2071 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2072 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2074 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2075 _mesa_error(ctx
, GL_INVALID_VALUE
,
2076 "%s(bindingindex=%u > "
2077 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2078 func
, bindingIndex
);
2082 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2087 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2089 GET_CURRENT_CONTEXT(ctx
);
2091 /* The ARB_vertex_attrib_binding spec says:
2093 * "An INVALID_OPERATION error is generated if no vertex array object
2096 if (ctx
->API
== API_OPENGL_CORE
&&
2097 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2098 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2099 "glVertexBindingDivisor(No array object bound)");
2103 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
2104 bindingIndex
, divisor
,
2105 "glVertexBindingDivisor");
2110 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
, GLuint divisor
)
2112 struct gl_vertex_array_object
*vao
;
2113 GET_CURRENT_CONTEXT(ctx
);
2115 /* The ARB_direct_state_access specification says:
2117 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2118 * if <vaobj> is not [compatibility profile: zero or] the name of an
2119 * existing vertex array object."
2121 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayBindingDivisor");
2125 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
2126 "glVertexArrayBindingDivisor");
2131 * Copy one client vertex array to another.
2134 _mesa_copy_client_array(struct gl_context
*ctx
,
2135 struct gl_client_array
*dst
,
2136 struct gl_client_array
*src
)
2138 dst
->Size
= src
->Size
;
2139 dst
->Type
= src
->Type
;
2140 dst
->Format
= src
->Format
;
2141 dst
->Stride
= src
->Stride
;
2142 dst
->StrideB
= src
->StrideB
;
2143 dst
->Ptr
= src
->Ptr
;
2144 dst
->Enabled
= src
->Enabled
;
2145 dst
->Normalized
= src
->Normalized
;
2146 dst
->Integer
= src
->Integer
;
2147 dst
->Doubles
= src
->Doubles
;
2148 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2149 dst
->_ElementSize
= src
->_ElementSize
;
2150 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2154 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2155 struct gl_vertex_attrib_array
*dst
,
2156 const struct gl_vertex_attrib_array
*src
)
2158 dst
->Size
= src
->Size
;
2159 dst
->Type
= src
->Type
;
2160 dst
->Format
= src
->Format
;
2161 dst
->VertexBinding
= src
->VertexBinding
;
2162 dst
->RelativeOffset
= src
->RelativeOffset
;
2163 dst
->Format
= src
->Format
;
2164 dst
->Integer
= src
->Integer
;
2165 dst
->Doubles
= src
->Doubles
;
2166 dst
->Normalized
= src
->Normalized
;
2167 dst
->Ptr
= src
->Ptr
;
2168 dst
->Enabled
= src
->Enabled
;
2169 dst
->_ElementSize
= src
->_ElementSize
;
2173 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2174 struct gl_vertex_buffer_binding
*dst
,
2175 const struct gl_vertex_buffer_binding
*src
)
2177 dst
->Offset
= src
->Offset
;
2178 dst
->Stride
= src
->Stride
;
2179 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2180 dst
->_BoundArrays
= src
->_BoundArrays
;
2182 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2186 * Print vertex array's fields.
2189 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
2192 fprintf(stderr
, " %s[%d]: ", name
, index
);
2194 fprintf(stderr
, " %s: ", name
);
2195 fprintf(stderr
, "Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
2196 array
->Ptr
, array
->Type
, array
->Size
,
2197 array
->_ElementSize
, array
->StrideB
,
2198 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
);
2203 * Print current vertex object/array info. For debug.
2206 _mesa_print_arrays(struct gl_context
*ctx
)
2208 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2211 printf("Array Object %u\n", vao
->Name
);
2212 if (vao
->_VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
2213 print_array("Vertex", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_POS
]);
2214 if (vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
2215 print_array("Normal", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
]);
2216 if (vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
2217 print_array("Color", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
]);
2218 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
2219 if (vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
2220 print_array("TexCoord", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
2221 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
2222 if (vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
2223 print_array("Attrib", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
2228 * Initialize vertex array state for given context.
2231 _mesa_init_varray(struct gl_context
*ctx
)
2233 ctx
->Array
.DefaultVAO
= ctx
->Driver
.NewArrayObject(ctx
, 0);
2234 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2235 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2237 ctx
->Array
.Objects
= _mesa_NewHashTable();
2242 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2245 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2247 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2248 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2249 _mesa_delete_vao(ctx
, vao
);
2254 * Free vertex array state for given context.
2257 _mesa_free_varray_data(struct gl_context
*ctx
)
2259 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2260 _mesa_DeleteHashTable(ctx
->Array
.Objects
);