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
, GLuint bindingIndex
,
190 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
191 struct gl_vertex_buffer_binding
*binding
=
192 &vao
->VertexBinding
[bindingIndex
];
194 if (binding
->InstanceDivisor
!= divisor
) {
195 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
196 binding
->InstanceDivisor
= divisor
;
197 vao
->NewArrays
|= binding
->_BoundArrays
;
203 * Examine the API profile and extensions to determine which types are legal
204 * for vertex arrays. This is called once from update_array_format().
207 get_legal_types_mask(const struct gl_context
*ctx
)
209 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
211 if (_mesa_is_gles(ctx
)) {
212 legalTypesMask
&= ~(FIXED_GL_BIT
|
214 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
216 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
217 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
218 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
219 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
220 * quite as trivial as we'd like because it uses a different enum value
221 * for GL_HALF_FLOAT_OES.
223 if (ctx
->Version
< 30) {
224 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
226 UNSIGNED_INT_2_10_10_10_REV_BIT
|
227 INT_2_10_10_10_REV_BIT
|
232 legalTypesMask
&= ~FIXED_ES_BIT
;
234 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
235 legalTypesMask
&= ~FIXED_GL_BIT
;
237 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
238 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
239 INT_2_10_10_10_REV_BIT
);
241 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
242 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
245 return legalTypesMask
;
250 * Does error checking and updates the format in an attrib array.
252 * Called by update_array() and VertexAttrib*Format().
254 * \param func Name of calling function used for error reporting
255 * \param attrib The index of the attribute array
256 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
257 * \param sizeMin Min allowable size value
258 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
259 * \param size Components per element (1, 2, 3 or 4)
260 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
261 * \param normalized Whether integer types are converted to floats in [-1, 1]
262 * \param integer Integer-valued values (will not be normalized to [-1, 1])
263 * \param doubles Double values not reduced to floats
264 * \param relativeOffset Offset of the first element relative to the binding offset.
267 update_array_format(struct gl_context
*ctx
,
269 struct gl_vertex_array_object
*vao
,
270 GLuint attrib
, GLbitfield legalTypesMask
,
271 GLint sizeMin
, GLint sizeMax
,
272 GLint size
, GLenum type
,
273 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
274 GLuint relativeOffset
)
276 struct gl_vertex_attrib_array
*array
;
279 GLenum format
= GL_RGBA
;
281 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
282 /* Compute the LegalTypesMask only once, unless the context API has
283 * changed, in which case we want to compute it again. We can't do this
284 * in _mesa_init_varrays() below because extensions are not yet enabled
287 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
288 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
291 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
293 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
294 /* BGRA ordering is not supported in ES contexts.
299 typeBit
= type_to_bit(ctx
, type
);
300 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
301 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
302 func
, _mesa_lookup_enum_by_nr(type
));
306 /* Do size parameter checking.
307 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
308 * must be handled specially.
310 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
311 sizeMax
== BGRA_OR_4
&&
313 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
315 * "An INVALID_OPERATION error is generated under any of the following
318 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
319 * or UNSIGNED_INT_2_10_10_10_REV;
321 * • size is BGRA and normalized is FALSE;"
323 bool bgra_error
= false;
325 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
326 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
327 type
!= GL_INT_2_10_10_10_REV
&&
328 type
!= GL_UNSIGNED_BYTE
)
330 } else if (type
!= GL_UNSIGNED_BYTE
)
334 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
335 func
, _mesa_lookup_enum_by_nr(type
));
340 _mesa_error(ctx
, GL_INVALID_OPERATION
,
341 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
348 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
349 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
353 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
354 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
355 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
356 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
360 /* The ARB_vertex_attrib_binding_spec says:
362 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
363 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
365 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
366 _mesa_error(ctx
, GL_INVALID_VALUE
,
367 "%s(relativeOffset=%d > "
368 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
369 func
, relativeOffset
);
373 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
374 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
375 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
381 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
382 assert(elementSize
!= -1);
384 array
= &vao
->VertexAttrib
[attrib
];
387 array
->Format
= format
;
388 array
->Normalized
= normalized
;
389 array
->Integer
= integer
;
390 array
->Doubles
= doubles
;
391 array
->RelativeOffset
= relativeOffset
;
392 array
->_ElementSize
= elementSize
;
394 vao
->NewArrays
|= VERT_BIT(attrib
);
395 ctx
->NewState
|= _NEW_ARRAY
;
402 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
405 * \param func name of calling function used for error reporting
406 * \param attrib the attribute array index to update
407 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
408 * \param sizeMin min allowable size value
409 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
410 * \param size components per element (1, 2, 3 or 4)
411 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
412 * \param stride stride between elements, in elements
413 * \param normalized are integer types converted to floats in [-1, 1]?
414 * \param integer integer-valued values (will not be normalized to [-1,1])
415 * \param doubles Double values not reduced to floats
416 * \param ptr the address (or offset inside VBO) of the array data
419 update_array(struct gl_context
*ctx
,
421 GLuint attrib
, GLbitfield legalTypesMask
,
422 GLint sizeMin
, GLint sizeMax
,
423 GLint size
, GLenum type
, GLsizei stride
,
424 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
427 struct gl_vertex_attrib_array
*array
;
428 GLsizei effectiveStride
;
430 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
432 * "Client vertex arrays - all vertex array attribute pointers must
433 * refer to buffer objects (section 2.9.2). The default vertex array
434 * object (the name zero) is also deprecated. Calling
435 * VertexAttribPointer when no buffer object or no vertex array object
436 * is bound will generate an INVALID_OPERATION error..."
438 * The check for VBOs is handled below.
440 if (ctx
->API
== API_OPENGL_CORE
441 && (ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
)) {
442 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
448 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
452 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
453 stride
> ctx
->Const
.MaxVertexAttribStride
) {
454 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
455 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
459 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
461 * "An INVALID_OPERATION error is generated under any of the following
466 * * any of the *Pointer commands specifying the location and
467 * organization of vertex array data are called while zero is bound
468 * to the ARRAY_BUFFER buffer object binding point (see section
469 * 2.9.6), and the pointer argument is not NULL."
471 if (ptr
!= NULL
&& ctx
->Array
.VAO
->ARBsemantics
&&
472 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
473 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
477 if (!update_array_format(ctx
, func
, ctx
->Array
.VAO
, attrib
,
478 legalTypesMask
, sizeMin
, sizeMax
,
479 size
, type
, normalized
, integer
, doubles
, 0)) {
483 /* Reset the vertex attrib binding */
484 vertex_attrib_binding(ctx
, ctx
->Array
.VAO
, attrib
, attrib
);
486 /* The Stride and Ptr fields are not set by update_array_format() */
487 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
488 array
->Stride
= stride
;
489 array
->Ptr
= (const GLvoid
*) ptr
;
491 /* Update the vertex buffer binding */
492 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
493 bind_vertex_buffer(ctx
, ctx
->Array
.VAO
, attrib
, ctx
->Array
.ArrayBufferObj
,
494 (GLintptr
) ptr
, effectiveStride
);
499 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
501 GET_CURRENT_CONTEXT(ctx
);
502 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
503 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
504 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
505 DOUBLE_BIT
| HALF_BIT
|
506 UNSIGNED_INT_2_10_10_10_REV_BIT
|
507 INT_2_10_10_10_REV_BIT
);
509 FLUSH_VERTICES(ctx
, 0);
511 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
513 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
518 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
520 GET_CURRENT_CONTEXT(ctx
);
521 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
522 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
523 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
524 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
525 UNSIGNED_INT_2_10_10_10_REV_BIT
|
526 INT_2_10_10_10_REV_BIT
);
528 FLUSH_VERTICES(ctx
, 0);
530 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
532 3, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
537 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
539 GET_CURRENT_CONTEXT(ctx
);
540 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
541 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
542 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
543 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
544 INT_BIT
| UNSIGNED_INT_BIT
|
545 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
546 UNSIGNED_INT_2_10_10_10_REV_BIT
|
547 INT_2_10_10_10_REV_BIT
);
548 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
550 FLUSH_VERTICES(ctx
, 0);
552 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
553 legalTypes
, sizeMin
, BGRA_OR_4
,
554 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
559 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
561 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
562 GET_CURRENT_CONTEXT(ctx
);
564 FLUSH_VERTICES(ctx
, 0);
566 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
568 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
573 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
575 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
576 FLOAT_BIT
| DOUBLE_BIT
);
577 GET_CURRENT_CONTEXT(ctx
);
579 FLUSH_VERTICES(ctx
, 0);
581 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
583 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
588 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
589 GLsizei stride
, const GLvoid
*ptr
)
591 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
592 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
593 INT_BIT
| UNSIGNED_INT_BIT
|
594 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
595 UNSIGNED_INT_2_10_10_10_REV_BIT
|
596 INT_2_10_10_10_REV_BIT
);
597 GET_CURRENT_CONTEXT(ctx
);
599 FLUSH_VERTICES(ctx
, 0);
601 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
602 legalTypes
, 3, BGRA_OR_4
,
603 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
608 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
611 GET_CURRENT_CONTEXT(ctx
);
612 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
613 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
614 : (SHORT_BIT
| INT_BIT
|
615 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
616 UNSIGNED_INT_2_10_10_10_REV_BIT
|
617 INT_2_10_10_10_REV_BIT
);
618 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
619 const GLuint unit
= ctx
->Array
.ActiveTexture
;
621 FLUSH_VERTICES(ctx
, 0);
623 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
624 legalTypes
, sizeMin
, 4,
625 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
631 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
633 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
634 /* this is the same type that glEdgeFlag uses */
635 const GLboolean integer
= GL_FALSE
;
636 GET_CURRENT_CONTEXT(ctx
);
638 FLUSH_VERTICES(ctx
, 0);
640 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
642 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
647 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
649 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
650 GET_CURRENT_CONTEXT(ctx
);
652 FLUSH_VERTICES(ctx
, 0);
654 if (ctx
->API
!= API_OPENGLES
) {
655 _mesa_error(ctx
, GL_INVALID_OPERATION
,
656 "glPointSizePointer(ES 1.x only)");
660 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
662 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
667 * Set a generic vertex attribute array.
668 * Note that these arrays DO NOT alias the conventional GL vertex arrays
669 * (position, normal, color, fog, texcoord, etc).
672 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
673 GLboolean normalized
,
674 GLsizei stride
, const GLvoid
*ptr
)
676 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
677 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
678 INT_BIT
| UNSIGNED_INT_BIT
|
679 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
680 FIXED_ES_BIT
| FIXED_GL_BIT
|
681 UNSIGNED_INT_2_10_10_10_REV_BIT
|
682 INT_2_10_10_10_REV_BIT
|
683 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
684 GET_CURRENT_CONTEXT(ctx
);
686 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
687 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
691 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
692 legalTypes
, 1, BGRA_OR_4
,
693 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
698 * GL_EXT_gpu_shader4 / GL 3.0.
699 * Set an integer-valued vertex attribute array.
700 * Note that these arrays DO NOT alias the conventional GL vertex arrays
701 * (position, normal, color, fog, texcoord, etc).
704 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
705 GLsizei stride
, const GLvoid
*ptr
)
707 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
708 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
709 INT_BIT
| UNSIGNED_INT_BIT
);
710 const GLboolean normalized
= GL_FALSE
;
711 const GLboolean integer
= GL_TRUE
;
712 GET_CURRENT_CONTEXT(ctx
);
714 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
715 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
719 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
721 size
, type
, stride
, normalized
, integer
, GL_FALSE
, ptr
);
725 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
726 GLsizei stride
, const GLvoid
*ptr
)
728 GET_CURRENT_CONTEXT(ctx
);
729 const GLbitfield legalTypes
= (DOUBLE_BIT
);
730 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
731 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
735 update_array(ctx
, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index
),
737 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_TRUE
, ptr
);
742 enable_vertex_array_attrib(struct gl_context
*ctx
,
743 struct gl_vertex_array_object
*vao
,
747 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
748 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
752 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
754 if (!vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
755 /* was disabled, now being enabled */
756 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
757 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
758 vao
->_Enabled
|= VERT_BIT_GENERIC(index
);
759 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
765 _mesa_EnableVertexAttribArray(GLuint index
)
767 GET_CURRENT_CONTEXT(ctx
);
768 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
769 "glEnableVertexAttribArray");
774 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
776 GET_CURRENT_CONTEXT(ctx
);
777 struct gl_vertex_array_object
*vao
;
779 /* The ARB_direct_state_access specification says:
781 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
782 * and DisableVertexArrayAttrib if <vaobj> is not
783 * [compatibility profile: zero or] the name of an existing vertex
786 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
790 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
795 disable_vertex_array_attrib(struct gl_context
*ctx
,
796 struct gl_vertex_array_object
*vao
,
800 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
801 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
805 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
807 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
808 /* was enabled, now being disabled */
809 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
810 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
811 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
812 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
818 _mesa_DisableVertexAttribArray(GLuint index
)
820 GET_CURRENT_CONTEXT(ctx
);
821 disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
822 "glDisableVertexAttribArray");
827 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
829 GET_CURRENT_CONTEXT(ctx
);
830 struct gl_vertex_array_object
*vao
;
832 /* The ARB_direct_state_access specification says:
834 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
835 * and DisableVertexArrayAttrib if <vaobj> is not
836 * [compatibility profile: zero or] the name of an existing vertex
839 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
843 disable_vertex_array_attrib(ctx
, vao
, index
, "glDisableVertexArrayAttrib");
848 * Return info for a vertex attribute array (no alias with legacy
849 * vertex attributes (pos, normal, color, etc)). This function does
850 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
853 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
856 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
857 const struct gl_vertex_attrib_array
*array
;
859 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
860 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
864 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
866 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
869 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
870 return array
->Enabled
;
871 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
872 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
873 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
874 return array
->Stride
;
875 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
877 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
878 return array
->Normalized
;
879 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
880 return vao
->VertexBinding
[array
->VertexBinding
].BufferObj
->Name
;
881 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
882 if ((_mesa_is_desktop_gl(ctx
)
883 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
884 || _mesa_is_gles3(ctx
)) {
885 return array
->Integer
;
888 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
889 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
890 || _mesa_is_gles3(ctx
)) {
891 return vao
->VertexBinding
[array
->VertexBinding
].InstanceDivisor
;
894 case GL_VERTEX_ATTRIB_BINDING
:
895 if (_mesa_is_desktop_gl(ctx
)) {
896 return array
->VertexBinding
- VERT_ATTRIB_GENERIC0
;
899 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
900 if (_mesa_is_desktop_gl(ctx
)) {
901 return array
->RelativeOffset
;
909 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
914 static const GLfloat
*
915 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
918 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
919 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
923 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
924 _mesa_error(ctx
, GL_INVALID_VALUE
,
925 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
929 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
931 FLUSH_CURRENT(ctx
, 0);
932 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
936 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
938 GET_CURRENT_CONTEXT(ctx
);
940 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
941 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
947 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
948 "glGetVertexAttribfv");
954 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
956 GET_CURRENT_CONTEXT(ctx
);
958 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
959 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
961 params
[0] = (GLdouble
) v
[0];
962 params
[1] = (GLdouble
) v
[1];
963 params
[2] = (GLdouble
) v
[2];
964 params
[3] = (GLdouble
) v
[3];
968 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
969 "glGetVertexAttribdv");
974 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
976 GET_CURRENT_CONTEXT(ctx
);
978 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
979 const GLdouble
*v
= (const GLdouble
*)get_current_attrib(ctx
, index
, "glGetVertexAttribLdv");
988 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
989 "glGetVertexAttribLdv");
994 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
996 GET_CURRENT_CONTEXT(ctx
);
998 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
999 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1001 /* XXX should floats in[0,1] be scaled to full int range? */
1002 params
[0] = (GLint
) v
[0];
1003 params
[1] = (GLint
) v
[1];
1004 params
[2] = (GLint
) v
[2];
1005 params
[3] = (GLint
) v
[3];
1009 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
1010 "glGetVertexAttribiv");
1017 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1019 GET_CURRENT_CONTEXT(ctx
);
1021 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1022 const GLint
*v
= (const GLint
*)
1023 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1029 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
1030 "glGetVertexAttribIiv");
1037 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1039 GET_CURRENT_CONTEXT(ctx
);
1041 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1042 const GLuint
*v
= (const GLuint
*)
1043 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1049 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
1050 "glGetVertexAttribIuiv");
1056 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1058 GET_CURRENT_CONTEXT(ctx
);
1060 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1061 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1065 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1066 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1070 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1072 *pointer
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1077 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1078 GLsizei count
, const GLvoid
*ptr
)
1081 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1086 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1090 _mesa_NormalPointer(type
, stride
, ptr
);
1095 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1099 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1104 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1108 _mesa_IndexPointer(type
, stride
, ptr
);
1113 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1114 GLsizei count
, const GLvoid
*ptr
)
1117 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1122 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1125 _mesa_EdgeFlagPointer(stride
, ptr
);
1130 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1132 GET_CURRENT_CONTEXT(ctx
);
1133 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1134 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1135 GLenum ctype
= 0; /* color type */
1136 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1137 const GLint toffset
= 0; /* always zero */
1138 GLint defstride
; /* default stride */
1141 FLUSH_VERTICES(ctx
, 0);
1143 f
= sizeof(GLfloat
);
1144 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1147 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1153 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1154 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1159 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1160 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1165 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1166 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1167 ctype
= GL_UNSIGNED_BYTE
;
1170 defstride
= c
+ 2*f
;
1173 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1174 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1175 ctype
= GL_UNSIGNED_BYTE
;
1178 defstride
= c
+ 3*f
;
1181 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1182 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1189 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1190 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1195 case GL_C4F_N3F_V3F
:
1196 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1197 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1205 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1206 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1211 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1212 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1216 case GL_T2F_C4UB_V3F
:
1217 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1218 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1219 ctype
= GL_UNSIGNED_BYTE
;
1224 case GL_T2F_C3F_V3F
:
1225 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1226 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1232 case GL_T2F_N3F_V3F
:
1233 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1234 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1239 case GL_T2F_C4F_N3F_V3F
:
1240 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1241 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1248 case GL_T4F_C4F_N3F_V4F
:
1249 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1250 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1258 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1266 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1267 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1268 /* XXX also disable secondary color and generic arrays? */
1272 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1273 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1274 (GLubyte
*) pointer
+ toffset
);
1277 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1282 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1283 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1284 (GLubyte
*) pointer
+ coffset
);
1287 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1293 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1294 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1297 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1301 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1302 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1303 (GLubyte
*) pointer
+ voffset
);
1308 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1310 GET_CURRENT_CONTEXT(ctx
);
1312 FLUSH_VERTICES(ctx
, 0);
1314 if (MESA_VERBOSE
& VERBOSE_API
)
1315 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1318 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1322 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1325 if (ctx
->Array
.LockCount
!= 0) {
1326 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1330 ctx
->Array
.LockFirst
= first
;
1331 ctx
->Array
.LockCount
= count
;
1333 ctx
->NewState
|= _NEW_ARRAY
;
1338 _mesa_UnlockArraysEXT( void )
1340 GET_CURRENT_CONTEXT(ctx
);
1342 FLUSH_VERTICES(ctx
, 0);
1344 if (MESA_VERBOSE
& VERBOSE_API
)
1345 _mesa_debug(ctx
, "glUnlockArrays\n");
1347 if (ctx
->Array
.LockCount
== 0) {
1348 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1352 ctx
->Array
.LockFirst
= 0;
1353 ctx
->Array
.LockCount
= 0;
1354 ctx
->NewState
|= _NEW_ARRAY
;
1358 /* GL_EXT_multi_draw_arrays */
1360 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1361 const GLsizei
*count
, GLsizei primcount
)
1363 GET_CURRENT_CONTEXT(ctx
);
1366 FLUSH_VERTICES(ctx
, 0);
1368 for (i
= 0; i
< primcount
; i
++) {
1370 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1376 /* GL_IBM_multimode_draw_arrays */
1378 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1379 const GLsizei
* count
,
1380 GLsizei primcount
, GLint modestride
)
1382 GET_CURRENT_CONTEXT(ctx
);
1385 FLUSH_VERTICES(ctx
, 0);
1387 for ( i
= 0 ; i
< primcount
; i
++ ) {
1388 if ( count
[i
] > 0 ) {
1389 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1390 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1396 /* GL_IBM_multimode_draw_arrays */
1398 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1399 GLenum type
, const GLvoid
* const * indices
,
1400 GLsizei primcount
, GLint modestride
)
1402 GET_CURRENT_CONTEXT(ctx
);
1405 FLUSH_VERTICES(ctx
, 0);
1407 /* XXX not sure about ARB_vertex_buffer_object handling here */
1409 for ( i
= 0 ; i
< primcount
; i
++ ) {
1410 if ( count
[i
] > 0 ) {
1411 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1412 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1420 * GL_NV_primitive_restart and GL 3.1
1423 _mesa_PrimitiveRestartIndex(GLuint index
)
1425 GET_CURRENT_CONTEXT(ctx
);
1427 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1428 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1432 if (ctx
->Array
.RestartIndex
!= index
) {
1433 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1434 ctx
->Array
.RestartIndex
= index
;
1440 * See GL_ARB_instanced_arrays.
1441 * Note that the instance divisor only applies to generic arrays, not
1442 * the legacy vertex arrays.
1445 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1447 GET_CURRENT_CONTEXT(ctx
);
1449 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1450 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1452 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1453 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1457 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1458 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1463 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
1465 /* The ARB_vertex_attrib_binding spec says:
1469 * void VertexAttribDivisor(uint index, uint divisor);
1471 * is equivalent to (assuming no errors are generated):
1473 * VertexAttribBinding(index, index);
1474 * VertexBindingDivisor(index, divisor);"
1476 vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
1477 vertex_binding_divisor(ctx
, genericIndex
, divisor
);
1482 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1484 /* From the OpenGL 4.3 core specification, page 302:
1485 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1486 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1489 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1491 case GL_UNSIGNED_BYTE
:
1493 case GL_UNSIGNED_SHORT
:
1495 case GL_UNSIGNED_INT
:
1498 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1502 return ctx
->Array
.RestartIndex
;
1507 * GL_ARB_vertex_attrib_binding
1510 vertex_array_vertex_buffer(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
,
1511 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1512 GLsizei stride
, const char *func
)
1514 struct gl_buffer_object
*vbo
;
1516 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1518 /* The ARB_vertex_attrib_binding spec says:
1520 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1521 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1523 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1524 _mesa_error(ctx
, GL_INVALID_VALUE
,
1525 "%s(bindingindex=%u > "
1526 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1527 func
, bindingIndex
);
1531 /* The ARB_vertex_attrib_binding spec says:
1533 * "The error INVALID_VALUE is generated if <stride> or <offset>
1537 _mesa_error(ctx
, GL_INVALID_VALUE
,
1538 "%s(offset=%" PRId64
" < 0)",
1539 func
, (int64_t) offset
);
1544 _mesa_error(ctx
, GL_INVALID_VALUE
,
1545 "%s(stride=%d < 0)", func
, stride
);
1549 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1550 stride
> ctx
->Const
.MaxVertexAttribStride
) {
1551 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
1552 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
1556 if (buffer
== vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1557 vbo
= vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1558 } else if (buffer
!= 0) {
1559 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1561 /* From the GL_ARB_vertex_attrib_array spec:
1563 * "[Core profile only:]
1564 * An INVALID_OPERATION error is generated if buffer is not zero or a
1565 * name returned from a previous call to GenBuffers, or if such a name
1566 * has since been deleted with DeleteBuffers.
1568 * Otherwise, we fall back to the same compat profile behavior as other
1569 * object references (automatically gen it).
1571 if (!_mesa_handle_bind_buffer_gen(ctx
, GL_ARRAY_BUFFER
, buffer
,
1575 /* The ARB_vertex_attrib_binding spec says:
1577 * "If <buffer> is zero, any buffer object attached to this
1578 * bindpoint is detached."
1580 vbo
= ctx
->Shared
->NullBufferObj
;
1583 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
1584 vbo
, offset
, stride
);
1589 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1592 GET_CURRENT_CONTEXT(ctx
);
1594 /* The ARB_vertex_attrib_binding spec says:
1596 * "An INVALID_OPERATION error is generated if no vertex array object
1599 if (ctx
->API
== API_OPENGL_CORE
&&
1600 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1601 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1602 "glBindVertexBuffer(No array object bound)");
1606 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
1607 buffer
, offset
, stride
, "glBindVertexBuffer");
1612 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
1613 GLintptr offset
, GLsizei stride
)
1615 GET_CURRENT_CONTEXT(ctx
);
1616 struct gl_vertex_array_object
*vao
;
1618 /* The ARB_direct_state_access specification says:
1620 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1621 * if <vaobj> is not [compatibility profile: zero or] the name of an
1622 * existing vertex array object."
1624 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
1628 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
,
1629 buffer
, offset
, stride
,
1630 "glVertexArrayVertexBuffer");
1635 vertex_array_vertex_buffers(struct gl_context
*ctx
,
1636 struct gl_vertex_array_object
*vao
,
1637 GLuint first
, GLsizei count
, const GLuint
*buffers
,
1638 const GLintptr
*offsets
, const GLsizei
*strides
,
1643 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1645 /* The ARB_multi_bind spec says:
1647 * "An INVALID_OPERATION error is generated if <first> + <count>
1648 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1650 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1651 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1652 "%s(first=%u + count=%d > the value of "
1653 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1654 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1660 * The ARB_multi_bind spec says:
1662 * "If <buffers> is NULL, each affected vertex buffer binding point
1663 * from <first> through <first>+<count>-1 will be reset to have no
1664 * bound buffer object. In this case, the offsets and strides
1665 * associated with the binding points are set to default values,
1666 * ignoring <offsets> and <strides>."
1668 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1670 for (i
= 0; i
< count
; i
++)
1671 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1677 /* Note that the error semantics for multi-bind commands differ from
1678 * those of other GL commands.
1680 * The Issues section in the ARB_multi_bind spec says:
1682 * "(11) Typically, OpenGL specifies that if an error is generated by
1683 * a command, that command has no effect. This is somewhat
1684 * unfortunate for multi-bind commands, because it would require
1685 * a first pass to scan the entire list of bound objects for
1686 * errors and then a second pass to actually perform the
1687 * bindings. Should we have different error semantics?
1689 * RESOLVED: Yes. In this specification, when the parameters for
1690 * one of the <count> binding points are invalid, that binding
1691 * point is not updated and an error will be generated. However,
1692 * other binding points in the same command will be updated if
1693 * their parameters are valid and no other error occurs."
1696 _mesa_begin_bufferobj_lookups(ctx
);
1698 for (i
= 0; i
< count
; i
++) {
1699 struct gl_buffer_object
*vbo
;
1701 /* The ARB_multi_bind spec says:
1703 * "An INVALID_VALUE error is generated if any value in
1704 * <offsets> or <strides> is negative (per binding)."
1706 if (offsets
[i
] < 0) {
1707 _mesa_error(ctx
, GL_INVALID_VALUE
,
1708 "%s(offsets[%u]=%" PRId64
" < 0)",
1709 func
, i
, (int64_t) offsets
[i
]);
1713 if (strides
[i
] < 0) {
1714 _mesa_error(ctx
, GL_INVALID_VALUE
,
1715 "%s(strides[%u]=%d < 0)",
1716 func
, i
, strides
[i
]);
1720 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1721 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
1722 _mesa_error(ctx
, GL_INVALID_VALUE
,
1723 "%s(strides[%u]=%d > "
1724 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
1729 struct gl_vertex_buffer_binding
*binding
=
1730 &vao
->VertexBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1732 if (buffers
[i
] == binding
->BufferObj
->Name
)
1733 vbo
= binding
->BufferObj
;
1735 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
1740 vbo
= ctx
->Shared
->NullBufferObj
;
1743 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1744 vbo
, offsets
[i
], strides
[i
]);
1747 _mesa_end_bufferobj_lookups(ctx
);
1752 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1753 const GLintptr
*offsets
, const GLsizei
*strides
)
1755 GET_CURRENT_CONTEXT(ctx
);
1757 /* The ARB_vertex_attrib_binding spec says:
1759 * "An INVALID_OPERATION error is generated if no
1760 * vertex array object is bound."
1762 if (ctx
->API
== API_OPENGL_CORE
&&
1763 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1764 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1765 "glBindVertexBuffers(No array object bound)");
1769 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
1770 buffers
, offsets
, strides
,
1771 "glBindVertexBuffers");
1776 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
1777 const GLuint
*buffers
,
1778 const GLintptr
*offsets
, const GLsizei
*strides
)
1780 GET_CURRENT_CONTEXT(ctx
);
1781 struct gl_vertex_array_object
*vao
;
1783 /* The ARB_direct_state_access specification says:
1785 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1786 * if <vaobj> is not [compatibility profile: zero or] the name of an
1787 * existing vertex array object."
1789 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
1793 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
1794 buffers
, offsets
, strides
,
1795 "glVertexArrayVertexBuffers");
1800 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
1801 GLboolean normalized
, GLboolean integer
,
1802 GLboolean doubles
, GLbitfield legalTypes
,
1803 GLsizei maxSize
, GLuint relativeOffset
,
1806 GET_CURRENT_CONTEXT(ctx
);
1807 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1809 /* The ARB_vertex_attrib_binding spec says:
1811 * "An INVALID_OPERATION error is generated under any of the following
1813 * - if no vertex array object is currently bound (see section 2.10);
1816 * This error condition only applies to VertexAttribFormat and
1817 * VertexAttribIFormat in the extension spec, but we assume that this
1818 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
1819 * to all three functions.
1821 if (ctx
->API
== API_OPENGL_CORE
&&
1822 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1823 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1824 "%s(No array object bound)", func
);
1828 /* The ARB_vertex_attrib_binding spec says:
1830 * "The error INVALID_VALUE is generated if index is greater than or equal
1831 * to the value of MAX_VERTEX_ATTRIBS."
1833 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1834 _mesa_error(ctx
, GL_INVALID_VALUE
,
1835 "%s(attribindex=%u > "
1836 "GL_MAX_VERTEX_ATTRIBS)",
1841 FLUSH_VERTICES(ctx
, 0);
1843 update_array_format(ctx
, func
, ctx
->Array
.VAO
,
1844 VERT_ATTRIB_GENERIC(attribIndex
),
1845 legalTypes
, 1, maxSize
, size
, type
,
1846 normalized
, integer
, doubles
, relativeOffset
);
1851 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1852 GLboolean normalized
, GLuint relativeOffset
)
1854 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
1855 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
1856 BGRA_OR_4
, relativeOffset
,
1857 "glVertexAttribFormat");
1862 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1863 GLuint relativeOffset
)
1865 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
1866 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
1867 relativeOffset
, "glVertexAttribIFormat");
1872 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1873 GLuint relativeOffset
)
1875 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
1876 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
1877 relativeOffset
, "glVertexAttribLFormat");
1882 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
1883 GLenum type
, GLboolean normalized
,
1884 GLboolean integer
, GLboolean doubles
,
1885 GLbitfield legalTypes
, GLsizei maxSize
,
1886 GLuint relativeOffset
, const char *func
)
1888 GET_CURRENT_CONTEXT(ctx
);
1889 struct gl_vertex_array_object
*vao
;
1891 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1893 /* The ARB_direct_state_access spec says:
1895 * "An INVALID_OPERATION error is generated by VertexArrayAttrib*Format
1896 * if <vaobj> is not [compatibility profile: zero or] the name of an
1897 * existing vertex array object."
1899 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
1903 /* The ARB_vertex_attrib_binding spec says:
1905 * "The error INVALID_VALUE is generated if index is greater than or equal
1906 * to the value of MAX_VERTEX_ATTRIBS."
1908 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1909 _mesa_error(ctx
, GL_INVALID_VALUE
,
1910 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
1915 FLUSH_VERTICES(ctx
, 0);
1917 update_array_format(ctx
, func
, vao
,
1918 VERT_ATTRIB_GENERIC(attribIndex
),
1919 legalTypes
, 1, maxSize
, size
, type
, normalized
,
1920 integer
, doubles
, relativeOffset
);
1925 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
1926 GLenum type
, GLboolean normalized
,
1927 GLuint relativeOffset
)
1929 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
1930 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
1931 BGRA_OR_4
, relativeOffset
,
1932 "glVertexArrayAttribFormat");
1937 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
1938 GLint size
, GLenum type
,
1939 GLuint relativeOffset
)
1941 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
1942 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
1944 "glVertexArrayAttribIFormat");
1949 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
1950 GLint size
, GLenum type
,
1951 GLuint relativeOffset
)
1953 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
1954 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
1956 "glVertexArrayAttribLFormat");
1961 vertex_array_attrib_binding(struct gl_context
*ctx
,
1962 struct gl_vertex_array_object
*vao
,
1963 GLuint attribIndex
, GLuint bindingIndex
,
1966 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1968 /* The ARB_vertex_attrib_binding spec says:
1970 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1971 * <bindingindex> must be less than the value of
1972 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1975 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1976 _mesa_error(ctx
, GL_INVALID_VALUE
,
1977 "%s(attribindex=%u >= "
1978 "GL_MAX_VERTEX_ATTRIBS)",
1983 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1984 _mesa_error(ctx
, GL_INVALID_VALUE
,
1985 "%s(bindingindex=%u >= "
1986 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1987 func
, bindingIndex
);
1991 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
1993 vertex_attrib_binding(ctx
, vao
,
1994 VERT_ATTRIB_GENERIC(attribIndex
),
1995 VERT_ATTRIB_GENERIC(bindingIndex
));
2000 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2002 GET_CURRENT_CONTEXT(ctx
);
2004 /* The ARB_vertex_attrib_binding spec says:
2006 * "An INVALID_OPERATION error is generated if no vertex array object
2009 if (ctx
->API
== API_OPENGL_CORE
&&
2010 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2011 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2012 "glVertexAttribBinding(No array object bound)");
2016 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2017 attribIndex
, bindingIndex
,
2018 "glVertexAttribBinding");
2023 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2025 GET_CURRENT_CONTEXT(ctx
);
2026 struct gl_vertex_array_object
*vao
;
2028 /* The ARB_direct_state_access specification says:
2030 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2031 * if <vaobj> is not [compatibility profile: zero or] the name of an
2032 * existing vertex array object."
2034 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2038 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2039 "glVertexArrayAttribBinding");
2044 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2046 GET_CURRENT_CONTEXT(ctx
);
2047 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2049 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2050 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexBindingDivisor()");
2054 /* The ARB_vertex_attrib_binding spec says:
2056 * "An INVALID_OPERATION error is generated if no vertex array object
2059 if (ctx
->API
== API_OPENGL_CORE
&&
2060 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2061 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2062 "glVertexBindingDivisor(No array object bound)");
2066 /* The ARB_vertex_attrib_binding spec says:
2068 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2069 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2071 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2072 _mesa_error(ctx
, GL_INVALID_VALUE
,
2073 "glVertexBindingDivisor(bindingindex=%u > "
2074 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2079 vertex_binding_divisor(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2084 * Copy one client vertex array to another.
2087 _mesa_copy_client_array(struct gl_context
*ctx
,
2088 struct gl_client_array
*dst
,
2089 struct gl_client_array
*src
)
2091 dst
->Size
= src
->Size
;
2092 dst
->Type
= src
->Type
;
2093 dst
->Format
= src
->Format
;
2094 dst
->Stride
= src
->Stride
;
2095 dst
->StrideB
= src
->StrideB
;
2096 dst
->Ptr
= src
->Ptr
;
2097 dst
->Enabled
= src
->Enabled
;
2098 dst
->Normalized
= src
->Normalized
;
2099 dst
->Integer
= src
->Integer
;
2100 dst
->Doubles
= src
->Doubles
;
2101 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2102 dst
->_ElementSize
= src
->_ElementSize
;
2103 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2107 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2108 struct gl_vertex_attrib_array
*dst
,
2109 const struct gl_vertex_attrib_array
*src
)
2111 dst
->Size
= src
->Size
;
2112 dst
->Type
= src
->Type
;
2113 dst
->Format
= src
->Format
;
2114 dst
->VertexBinding
= src
->VertexBinding
;
2115 dst
->RelativeOffset
= src
->RelativeOffset
;
2116 dst
->Format
= src
->Format
;
2117 dst
->Integer
= src
->Integer
;
2118 dst
->Doubles
= src
->Doubles
;
2119 dst
->Normalized
= src
->Normalized
;
2120 dst
->Ptr
= src
->Ptr
;
2121 dst
->Enabled
= src
->Enabled
;
2122 dst
->_ElementSize
= src
->_ElementSize
;
2126 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2127 struct gl_vertex_buffer_binding
*dst
,
2128 const struct gl_vertex_buffer_binding
*src
)
2130 dst
->Offset
= src
->Offset
;
2131 dst
->Stride
= src
->Stride
;
2132 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2133 dst
->_BoundArrays
= src
->_BoundArrays
;
2135 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2139 * Print vertex array's fields.
2142 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
2145 fprintf(stderr
, " %s[%d]: ", name
, index
);
2147 fprintf(stderr
, " %s: ", name
);
2148 fprintf(stderr
, "Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
2149 array
->Ptr
, array
->Type
, array
->Size
,
2150 array
->_ElementSize
, array
->StrideB
,
2151 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
);
2156 * Print current vertex object/array info. For debug.
2159 _mesa_print_arrays(struct gl_context
*ctx
)
2161 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2164 printf("Array Object %u\n", vao
->Name
);
2165 if (vao
->_VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
2166 print_array("Vertex", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_POS
]);
2167 if (vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
2168 print_array("Normal", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
]);
2169 if (vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
2170 print_array("Color", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
]);
2171 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
2172 if (vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
2173 print_array("TexCoord", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
2174 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
2175 if (vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
2176 print_array("Attrib", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
2181 * Initialize vertex array state for given context.
2184 _mesa_init_varray(struct gl_context
*ctx
)
2186 ctx
->Array
.DefaultVAO
= ctx
->Driver
.NewArrayObject(ctx
, 0);
2187 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2188 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2190 ctx
->Array
.Objects
= _mesa_NewHashTable();
2195 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2198 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2200 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2201 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2202 _mesa_delete_vao(ctx
, vao
);
2207 * Free vertex array state for given context.
2210 _mesa_free_varray_data(struct gl_context
*ctx
)
2212 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2213 _mesa_DeleteHashTable(ctx
->Array
.Objects
);