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
, GLuint attribIndex
,
134 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
135 struct gl_vertex_attrib_array
*array
= &vao
->VertexAttrib
[attribIndex
];
137 if (array
->VertexBinding
!= bindingIndex
) {
138 const GLbitfield64 array_bit
= VERT_BIT(attribIndex
);
140 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
142 vao
->VertexBinding
[array
->VertexBinding
]._BoundArrays
&= ~array_bit
;
143 vao
->VertexBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
145 array
->VertexBinding
= bindingIndex
;
147 vao
->NewArrays
|= array_bit
;
153 * Binds a buffer object to the vertex buffer binding point given by index,
154 * and sets the Offset and Stride fields.
157 bind_vertex_buffer(struct gl_context
*ctx
,
158 struct gl_vertex_array_object
*vao
,
160 struct gl_buffer_object
*vbo
,
161 GLintptr offset
, GLsizei stride
)
163 struct gl_vertex_buffer_binding
*binding
= &vao
->VertexBinding
[index
];
165 if (binding
->BufferObj
!= vbo
||
166 binding
->Offset
!= offset
||
167 binding
->Stride
!= stride
) {
169 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
171 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
173 binding
->Offset
= offset
;
174 binding
->Stride
= stride
;
176 vao
->NewArrays
|= binding
->_BoundArrays
;
182 * Sets the InstanceDivisor field in the vertex buffer binding point
183 * given by bindingIndex.
186 vertex_binding_divisor(struct gl_context
*ctx
, GLuint bindingIndex
,
189 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
190 struct gl_vertex_buffer_binding
*binding
=
191 &vao
->VertexBinding
[bindingIndex
];
193 if (binding
->InstanceDivisor
!= divisor
) {
194 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
195 binding
->InstanceDivisor
= divisor
;
196 vao
->NewArrays
|= binding
->_BoundArrays
;
202 * Examine the API profile and extensions to determine which types are legal
203 * for vertex arrays. This is called once from update_array_format().
206 get_legal_types_mask(const struct gl_context
*ctx
)
208 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
210 if (_mesa_is_gles(ctx
)) {
211 legalTypesMask
&= ~(FIXED_GL_BIT
|
213 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
215 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
216 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
217 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
218 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
219 * quite as trivial as we'd like because it uses a different enum value
220 * for GL_HALF_FLOAT_OES.
222 if (ctx
->Version
< 30) {
223 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
225 UNSIGNED_INT_2_10_10_10_REV_BIT
|
226 INT_2_10_10_10_REV_BIT
|
231 legalTypesMask
&= ~FIXED_ES_BIT
;
233 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
234 legalTypesMask
&= ~FIXED_GL_BIT
;
236 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
237 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
238 INT_2_10_10_10_REV_BIT
);
240 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
241 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
244 return legalTypesMask
;
249 * Does error checking and updates the format in an attrib array.
251 * Called by update_array() and VertexAttrib*Format().
253 * \param func Name of calling function used for error reporting
254 * \param attrib The index of the attribute array
255 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
256 * \param sizeMin Min allowable size value
257 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
258 * \param size Components per element (1, 2, 3 or 4)
259 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
260 * \param normalized Whether integer types are converted to floats in [-1, 1]
261 * \param integer Integer-valued values (will not be normalized to [-1, 1])
262 * \param doubles Double values not reduced to floats
263 * \param relativeOffset Offset of the first element relative to the binding offset.
266 update_array_format(struct gl_context
*ctx
,
268 struct gl_vertex_array_object
*vao
,
269 GLuint attrib
, GLbitfield legalTypesMask
,
270 GLint sizeMin
, GLint sizeMax
,
271 GLint size
, GLenum type
,
272 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
273 GLuint relativeOffset
)
275 struct gl_vertex_attrib_array
*array
;
278 GLenum format
= GL_RGBA
;
280 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
281 /* Compute the LegalTypesMask only once, unless the context API has
282 * changed, in which case we want to compute it again. We can't do this
283 * in _mesa_init_varrays() below because extensions are not yet enabled
286 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
287 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
290 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
292 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
293 /* BGRA ordering is not supported in ES contexts.
298 typeBit
= type_to_bit(ctx
, type
);
299 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
300 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
301 func
, _mesa_lookup_enum_by_nr(type
));
305 /* Do size parameter checking.
306 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
307 * must be handled specially.
309 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
310 sizeMax
== BGRA_OR_4
&&
312 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
314 * "An INVALID_OPERATION error is generated under any of the following
317 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
318 * or UNSIGNED_INT_2_10_10_10_REV;
320 * • size is BGRA and normalized is FALSE;"
322 bool bgra_error
= false;
324 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
325 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
326 type
!= GL_INT_2_10_10_10_REV
&&
327 type
!= GL_UNSIGNED_BYTE
)
329 } else if (type
!= GL_UNSIGNED_BYTE
)
333 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
334 func
, _mesa_lookup_enum_by_nr(type
));
339 _mesa_error(ctx
, GL_INVALID_OPERATION
,
340 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
347 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
348 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
352 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
353 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
354 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
355 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
359 /* The ARB_vertex_attrib_binding_spec says:
361 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
362 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
364 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
365 _mesa_error(ctx
, GL_INVALID_VALUE
,
366 "%s(relativeOffset=%d > "
367 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
368 func
, relativeOffset
);
372 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
373 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
374 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
380 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
381 assert(elementSize
!= -1);
383 array
= &vao
->VertexAttrib
[attrib
];
386 array
->Format
= format
;
387 array
->Normalized
= normalized
;
388 array
->Integer
= integer
;
389 array
->Doubles
= doubles
;
390 array
->RelativeOffset
= relativeOffset
;
391 array
->_ElementSize
= elementSize
;
393 vao
->NewArrays
|= VERT_BIT(attrib
);
394 ctx
->NewState
|= _NEW_ARRAY
;
401 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
404 * \param func name of calling function used for error reporting
405 * \param attrib the attribute array index to update
406 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
407 * \param sizeMin min allowable size value
408 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
409 * \param size components per element (1, 2, 3 or 4)
410 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
411 * \param stride stride between elements, in elements
412 * \param normalized are integer types converted to floats in [-1, 1]?
413 * \param integer integer-valued values (will not be normalized to [-1,1])
414 * \param doubles Double values not reduced to floats
415 * \param ptr the address (or offset inside VBO) of the array data
418 update_array(struct gl_context
*ctx
,
420 GLuint attrib
, GLbitfield legalTypesMask
,
421 GLint sizeMin
, GLint sizeMax
,
422 GLint size
, GLenum type
, GLsizei stride
,
423 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
426 struct gl_vertex_attrib_array
*array
;
427 GLsizei effectiveStride
;
429 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
431 * "Client vertex arrays - all vertex array attribute pointers must
432 * refer to buffer objects (section 2.9.2). The default vertex array
433 * object (the name zero) is also deprecated. Calling
434 * VertexAttribPointer when no buffer object or no vertex array object
435 * is bound will generate an INVALID_OPERATION error..."
437 * The check for VBOs is handled below.
439 if (ctx
->API
== API_OPENGL_CORE
440 && (ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
)) {
441 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
447 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
451 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
452 stride
> ctx
->Const
.MaxVertexAttribStride
) {
453 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
454 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
458 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
460 * "An INVALID_OPERATION error is generated under any of the following
465 * * any of the *Pointer commands specifying the location and
466 * organization of vertex array data are called while zero is bound
467 * to the ARRAY_BUFFER buffer object binding point (see section
468 * 2.9.6), and the pointer argument is not NULL."
470 if (ptr
!= NULL
&& ctx
->Array
.VAO
->ARBsemantics
&&
471 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
472 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
476 if (!update_array_format(ctx
, func
, ctx
->Array
.VAO
, attrib
,
477 legalTypesMask
, sizeMin
, sizeMax
,
478 size
, type
, normalized
, integer
, doubles
, 0)) {
482 /* Reset the vertex attrib binding */
483 vertex_attrib_binding(ctx
, attrib
, attrib
);
485 /* The Stride and Ptr fields are not set by update_array_format() */
486 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
487 array
->Stride
= stride
;
488 array
->Ptr
= (const GLvoid
*) ptr
;
490 /* Update the vertex buffer binding */
491 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
492 bind_vertex_buffer(ctx
, ctx
->Array
.VAO
, attrib
, ctx
->Array
.ArrayBufferObj
,
493 (GLintptr
) ptr
, effectiveStride
);
498 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
500 GET_CURRENT_CONTEXT(ctx
);
501 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
502 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
503 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
504 DOUBLE_BIT
| HALF_BIT
|
505 UNSIGNED_INT_2_10_10_10_REV_BIT
|
506 INT_2_10_10_10_REV_BIT
);
508 FLUSH_VERTICES(ctx
, 0);
510 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
512 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
517 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
519 GET_CURRENT_CONTEXT(ctx
);
520 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
521 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
522 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
523 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
524 UNSIGNED_INT_2_10_10_10_REV_BIT
|
525 INT_2_10_10_10_REV_BIT
);
527 FLUSH_VERTICES(ctx
, 0);
529 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
531 3, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
536 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
538 GET_CURRENT_CONTEXT(ctx
);
539 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
540 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
541 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
542 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
543 INT_BIT
| UNSIGNED_INT_BIT
|
544 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
545 UNSIGNED_INT_2_10_10_10_REV_BIT
|
546 INT_2_10_10_10_REV_BIT
);
547 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
549 FLUSH_VERTICES(ctx
, 0);
551 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
552 legalTypes
, sizeMin
, BGRA_OR_4
,
553 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
558 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
560 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
561 GET_CURRENT_CONTEXT(ctx
);
563 FLUSH_VERTICES(ctx
, 0);
565 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
567 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
572 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
574 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
575 FLOAT_BIT
| DOUBLE_BIT
);
576 GET_CURRENT_CONTEXT(ctx
);
578 FLUSH_VERTICES(ctx
, 0);
580 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
582 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
587 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
588 GLsizei stride
, const GLvoid
*ptr
)
590 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
591 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
592 INT_BIT
| UNSIGNED_INT_BIT
|
593 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
594 UNSIGNED_INT_2_10_10_10_REV_BIT
|
595 INT_2_10_10_10_REV_BIT
);
596 GET_CURRENT_CONTEXT(ctx
);
598 FLUSH_VERTICES(ctx
, 0);
600 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
601 legalTypes
, 3, BGRA_OR_4
,
602 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
607 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
610 GET_CURRENT_CONTEXT(ctx
);
611 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
612 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
613 : (SHORT_BIT
| INT_BIT
|
614 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
615 UNSIGNED_INT_2_10_10_10_REV_BIT
|
616 INT_2_10_10_10_REV_BIT
);
617 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
618 const GLuint unit
= ctx
->Array
.ActiveTexture
;
620 FLUSH_VERTICES(ctx
, 0);
622 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
623 legalTypes
, sizeMin
, 4,
624 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
630 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
632 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
633 /* this is the same type that glEdgeFlag uses */
634 const GLboolean integer
= GL_FALSE
;
635 GET_CURRENT_CONTEXT(ctx
);
637 FLUSH_VERTICES(ctx
, 0);
639 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
641 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
646 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
648 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
649 GET_CURRENT_CONTEXT(ctx
);
651 FLUSH_VERTICES(ctx
, 0);
653 if (ctx
->API
!= API_OPENGLES
) {
654 _mesa_error(ctx
, GL_INVALID_OPERATION
,
655 "glPointSizePointer(ES 1.x only)");
659 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
661 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
666 * Set a generic vertex attribute array.
667 * Note that these arrays DO NOT alias the conventional GL vertex arrays
668 * (position, normal, color, fog, texcoord, etc).
671 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
672 GLboolean normalized
,
673 GLsizei stride
, const GLvoid
*ptr
)
675 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
676 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
677 INT_BIT
| UNSIGNED_INT_BIT
|
678 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
679 FIXED_ES_BIT
| FIXED_GL_BIT
|
680 UNSIGNED_INT_2_10_10_10_REV_BIT
|
681 INT_2_10_10_10_REV_BIT
|
682 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
683 GET_CURRENT_CONTEXT(ctx
);
685 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
686 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
690 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
691 legalTypes
, 1, BGRA_OR_4
,
692 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
697 * GL_EXT_gpu_shader4 / GL 3.0.
698 * Set an integer-valued vertex attribute array.
699 * Note that these arrays DO NOT alias the conventional GL vertex arrays
700 * (position, normal, color, fog, texcoord, etc).
703 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
704 GLsizei stride
, const GLvoid
*ptr
)
706 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
707 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
708 INT_BIT
| UNSIGNED_INT_BIT
);
709 const GLboolean normalized
= GL_FALSE
;
710 const GLboolean integer
= GL_TRUE
;
711 GET_CURRENT_CONTEXT(ctx
);
713 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
714 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
718 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
720 size
, type
, stride
, normalized
, integer
, GL_FALSE
, ptr
);
724 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
725 GLsizei stride
, const GLvoid
*ptr
)
727 GET_CURRENT_CONTEXT(ctx
);
728 const GLbitfield legalTypes
= (DOUBLE_BIT
);
729 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
730 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
734 update_array(ctx
, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index
),
736 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_TRUE
, ptr
);
741 enable_vertex_array_attrib(struct gl_context
*ctx
,
742 struct gl_vertex_array_object
*vao
,
746 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
747 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
751 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
753 if (!vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
754 /* was disabled, now being enabled */
755 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
756 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
757 vao
->_Enabled
|= VERT_BIT_GENERIC(index
);
758 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
764 _mesa_EnableVertexAttribArray(GLuint index
)
766 GET_CURRENT_CONTEXT(ctx
);
767 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
768 "glEnableVertexAttribArray");
773 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
775 GET_CURRENT_CONTEXT(ctx
);
776 struct gl_vertex_array_object
*vao
;
778 /* The ARB_direct_state_access specification says:
780 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
781 * and DisableVertexArrayAttrib if <vaobj> is not
782 * [compatibility profile: zero or] the name of an existing vertex
785 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
789 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
794 disable_vertex_array_attrib(struct gl_context
*ctx
,
795 struct gl_vertex_array_object
*vao
,
799 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
800 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
804 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
806 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
807 /* was enabled, now being disabled */
808 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
809 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
810 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
811 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
817 _mesa_DisableVertexAttribArray(GLuint index
)
819 GET_CURRENT_CONTEXT(ctx
);
820 disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
821 "glDisableVertexAttribArray");
826 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
828 GET_CURRENT_CONTEXT(ctx
);
829 struct gl_vertex_array_object
*vao
;
831 /* The ARB_direct_state_access specification says:
833 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
834 * and DisableVertexArrayAttrib if <vaobj> is not
835 * [compatibility profile: zero or] the name of an existing vertex
838 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
842 disable_vertex_array_attrib(ctx
, vao
, index
, "glDisableVertexArrayAttrib");
847 * Return info for a vertex attribute array (no alias with legacy
848 * vertex attributes (pos, normal, color, etc)). This function does
849 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
852 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
855 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
856 const struct gl_vertex_attrib_array
*array
;
858 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
859 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
863 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
865 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
868 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
869 return array
->Enabled
;
870 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
871 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
872 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
873 return array
->Stride
;
874 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
876 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
877 return array
->Normalized
;
878 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
879 return vao
->VertexBinding
[array
->VertexBinding
].BufferObj
->Name
;
880 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
881 if ((_mesa_is_desktop_gl(ctx
)
882 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
883 || _mesa_is_gles3(ctx
)) {
884 return array
->Integer
;
887 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
888 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
889 || _mesa_is_gles3(ctx
)) {
890 return vao
->VertexBinding
[array
->VertexBinding
].InstanceDivisor
;
893 case GL_VERTEX_ATTRIB_BINDING
:
894 if (_mesa_is_desktop_gl(ctx
)) {
895 return array
->VertexBinding
- VERT_ATTRIB_GENERIC0
;
898 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
899 if (_mesa_is_desktop_gl(ctx
)) {
900 return array
->RelativeOffset
;
908 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
913 static const GLfloat
*
914 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
917 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
918 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
922 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
923 _mesa_error(ctx
, GL_INVALID_VALUE
,
924 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
928 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
930 FLUSH_CURRENT(ctx
, 0);
931 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
935 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
937 GET_CURRENT_CONTEXT(ctx
);
939 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
940 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
946 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
947 "glGetVertexAttribfv");
953 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
955 GET_CURRENT_CONTEXT(ctx
);
957 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
958 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
960 params
[0] = (GLdouble
) v
[0];
961 params
[1] = (GLdouble
) v
[1];
962 params
[2] = (GLdouble
) v
[2];
963 params
[3] = (GLdouble
) v
[3];
967 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
968 "glGetVertexAttribdv");
973 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
975 GET_CURRENT_CONTEXT(ctx
);
977 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
978 const GLdouble
*v
= (const GLdouble
*)get_current_attrib(ctx
, index
, "glGetVertexAttribLdv");
987 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
988 "glGetVertexAttribLdv");
993 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
995 GET_CURRENT_CONTEXT(ctx
);
997 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
998 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1000 /* XXX should floats in[0,1] be scaled to full int range? */
1001 params
[0] = (GLint
) v
[0];
1002 params
[1] = (GLint
) v
[1];
1003 params
[2] = (GLint
) v
[2];
1004 params
[3] = (GLint
) v
[3];
1008 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
1009 "glGetVertexAttribiv");
1016 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1018 GET_CURRENT_CONTEXT(ctx
);
1020 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1021 const GLint
*v
= (const GLint
*)
1022 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1028 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
1029 "glGetVertexAttribIiv");
1036 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1038 GET_CURRENT_CONTEXT(ctx
);
1040 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1041 const GLuint
*v
= (const GLuint
*)
1042 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1048 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
1049 "glGetVertexAttribIuiv");
1055 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1057 GET_CURRENT_CONTEXT(ctx
);
1059 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1060 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1064 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1065 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1069 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1071 *pointer
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1076 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1077 GLsizei count
, const GLvoid
*ptr
)
1080 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1085 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1089 _mesa_NormalPointer(type
, stride
, ptr
);
1094 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1098 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1103 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1107 _mesa_IndexPointer(type
, stride
, ptr
);
1112 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1113 GLsizei count
, const GLvoid
*ptr
)
1116 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1121 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1124 _mesa_EdgeFlagPointer(stride
, ptr
);
1129 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1131 GET_CURRENT_CONTEXT(ctx
);
1132 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1133 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1134 GLenum ctype
= 0; /* color type */
1135 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1136 const GLint toffset
= 0; /* always zero */
1137 GLint defstride
; /* default stride */
1140 FLUSH_VERTICES(ctx
, 0);
1142 f
= sizeof(GLfloat
);
1143 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1146 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1152 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1153 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1158 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1159 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1164 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1165 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1166 ctype
= GL_UNSIGNED_BYTE
;
1169 defstride
= c
+ 2*f
;
1172 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1173 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1174 ctype
= GL_UNSIGNED_BYTE
;
1177 defstride
= c
+ 3*f
;
1180 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1181 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1188 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1189 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1194 case GL_C4F_N3F_V3F
:
1195 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1196 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1204 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1205 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1210 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1211 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1215 case GL_T2F_C4UB_V3F
:
1216 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1217 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1218 ctype
= GL_UNSIGNED_BYTE
;
1223 case GL_T2F_C3F_V3F
:
1224 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1225 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1231 case GL_T2F_N3F_V3F
:
1232 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1233 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1238 case GL_T2F_C4F_N3F_V3F
:
1239 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1240 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1247 case GL_T4F_C4F_N3F_V4F
:
1248 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1249 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1257 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1265 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1266 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1267 /* XXX also disable secondary color and generic arrays? */
1271 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1272 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1273 (GLubyte
*) pointer
+ toffset
);
1276 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1281 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1282 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1283 (GLubyte
*) pointer
+ coffset
);
1286 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1292 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1293 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1296 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1300 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1301 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1302 (GLubyte
*) pointer
+ voffset
);
1307 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1309 GET_CURRENT_CONTEXT(ctx
);
1311 FLUSH_VERTICES(ctx
, 0);
1313 if (MESA_VERBOSE
& VERBOSE_API
)
1314 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1317 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1321 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1324 if (ctx
->Array
.LockCount
!= 0) {
1325 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1329 ctx
->Array
.LockFirst
= first
;
1330 ctx
->Array
.LockCount
= count
;
1332 ctx
->NewState
|= _NEW_ARRAY
;
1337 _mesa_UnlockArraysEXT( void )
1339 GET_CURRENT_CONTEXT(ctx
);
1341 FLUSH_VERTICES(ctx
, 0);
1343 if (MESA_VERBOSE
& VERBOSE_API
)
1344 _mesa_debug(ctx
, "glUnlockArrays\n");
1346 if (ctx
->Array
.LockCount
== 0) {
1347 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1351 ctx
->Array
.LockFirst
= 0;
1352 ctx
->Array
.LockCount
= 0;
1353 ctx
->NewState
|= _NEW_ARRAY
;
1357 /* GL_EXT_multi_draw_arrays */
1359 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1360 const GLsizei
*count
, GLsizei primcount
)
1362 GET_CURRENT_CONTEXT(ctx
);
1365 FLUSH_VERTICES(ctx
, 0);
1367 for (i
= 0; i
< primcount
; i
++) {
1369 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1375 /* GL_IBM_multimode_draw_arrays */
1377 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1378 const GLsizei
* count
,
1379 GLsizei primcount
, GLint modestride
)
1381 GET_CURRENT_CONTEXT(ctx
);
1384 FLUSH_VERTICES(ctx
, 0);
1386 for ( i
= 0 ; i
< primcount
; i
++ ) {
1387 if ( count
[i
] > 0 ) {
1388 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1389 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1395 /* GL_IBM_multimode_draw_arrays */
1397 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1398 GLenum type
, const GLvoid
* const * indices
,
1399 GLsizei primcount
, GLint modestride
)
1401 GET_CURRENT_CONTEXT(ctx
);
1404 FLUSH_VERTICES(ctx
, 0);
1406 /* XXX not sure about ARB_vertex_buffer_object handling here */
1408 for ( i
= 0 ; i
< primcount
; i
++ ) {
1409 if ( count
[i
] > 0 ) {
1410 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1411 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1419 * GL_NV_primitive_restart and GL 3.1
1422 _mesa_PrimitiveRestartIndex(GLuint index
)
1424 GET_CURRENT_CONTEXT(ctx
);
1426 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1427 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1431 if (ctx
->Array
.RestartIndex
!= index
) {
1432 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1433 ctx
->Array
.RestartIndex
= index
;
1439 * See GL_ARB_instanced_arrays.
1440 * Note that the instance divisor only applies to generic arrays, not
1441 * the legacy vertex arrays.
1444 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1446 GET_CURRENT_CONTEXT(ctx
);
1448 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1450 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1451 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1455 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1456 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1461 assert(genericIndex
< ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1463 /* The ARB_vertex_attrib_binding spec says:
1467 * void VertexAttribDivisor(uint index, uint divisor);
1469 * is equivalent to (assuming no errors are generated):
1471 * VertexAttribBinding(index, index);
1472 * VertexBindingDivisor(index, divisor);"
1474 vertex_attrib_binding(ctx
, genericIndex
, genericIndex
);
1475 vertex_binding_divisor(ctx
, genericIndex
, divisor
);
1480 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1482 /* From the OpenGL 4.3 core specification, page 302:
1483 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1484 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1487 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1489 case GL_UNSIGNED_BYTE
:
1491 case GL_UNSIGNED_SHORT
:
1493 case GL_UNSIGNED_INT
:
1496 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1500 return ctx
->Array
.RestartIndex
;
1505 * GL_ARB_vertex_attrib_binding
1508 vertex_array_vertex_buffer(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
,
1509 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1510 GLsizei stride
, const char *func
)
1512 struct gl_buffer_object
*vbo
;
1514 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1516 /* The ARB_vertex_attrib_binding spec says:
1518 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1519 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1521 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1522 _mesa_error(ctx
, GL_INVALID_VALUE
,
1523 "%s(bindingindex=%u > "
1524 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1525 func
, bindingIndex
);
1529 /* The ARB_vertex_attrib_binding spec says:
1531 * "The error INVALID_VALUE is generated if <stride> or <offset>
1535 _mesa_error(ctx
, GL_INVALID_VALUE
,
1536 "%s(offset=%" PRId64
" < 0)",
1537 func
, (int64_t) offset
);
1542 _mesa_error(ctx
, GL_INVALID_VALUE
,
1543 "%s(stride=%d < 0)", func
, stride
);
1547 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1548 stride
> ctx
->Const
.MaxVertexAttribStride
) {
1549 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
1550 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
1554 if (buffer
== vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1555 vbo
= vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1556 } else if (buffer
!= 0) {
1557 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1559 /* From the GL_ARB_vertex_attrib_array spec:
1561 * "[Core profile only:]
1562 * An INVALID_OPERATION error is generated if buffer is not zero or a
1563 * name returned from a previous call to GenBuffers, or if such a name
1564 * has since been deleted with DeleteBuffers.
1566 * Otherwise, we fall back to the same compat profile behavior as other
1567 * object references (automatically gen it).
1569 if (!_mesa_handle_bind_buffer_gen(ctx
, GL_ARRAY_BUFFER
, buffer
,
1573 /* The ARB_vertex_attrib_binding spec says:
1575 * "If <buffer> is zero, any buffer object attached to this
1576 * bindpoint is detached."
1578 vbo
= ctx
->Shared
->NullBufferObj
;
1581 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
1582 vbo
, offset
, stride
);
1587 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1590 GET_CURRENT_CONTEXT(ctx
);
1592 /* The ARB_vertex_attrib_binding spec says:
1594 * "An INVALID_OPERATION error is generated if no vertex array object
1597 if (ctx
->API
== API_OPENGL_CORE
&&
1598 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1599 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1600 "glBindVertexBuffer(No array object bound)");
1604 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
1605 buffer
, offset
, stride
, "glBindVertexBuffer");
1610 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
1611 GLintptr offset
, GLsizei stride
)
1613 GET_CURRENT_CONTEXT(ctx
);
1614 struct gl_vertex_array_object
*vao
;
1616 /* The ARB_direct_state_access specification says:
1618 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1619 * if <vaobj> is not [compatibility profile: zero or] the name of an
1620 * existing vertex array object."
1622 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
1626 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
,
1627 buffer
, offset
, stride
,
1628 "glVertexArrayVertexBuffer");
1633 vertex_array_vertex_buffers(struct gl_context
*ctx
,
1634 struct gl_vertex_array_object
*vao
,
1635 GLuint first
, GLsizei count
, const GLuint
*buffers
,
1636 const GLintptr
*offsets
, const GLsizei
*strides
,
1641 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1643 /* The ARB_multi_bind spec says:
1645 * "An INVALID_OPERATION error is generated if <first> + <count>
1646 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1648 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1649 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1650 "%s(first=%u + count=%d > the value of "
1651 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1652 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1658 * The ARB_multi_bind spec says:
1660 * "If <buffers> is NULL, each affected vertex buffer binding point
1661 * from <first> through <first>+<count>-1 will be reset to have no
1662 * bound buffer object. In this case, the offsets and strides
1663 * associated with the binding points are set to default values,
1664 * ignoring <offsets> and <strides>."
1666 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1668 for (i
= 0; i
< count
; i
++)
1669 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1675 /* Note that the error semantics for multi-bind commands differ from
1676 * those of other GL commands.
1678 * The Issues section in the ARB_multi_bind spec says:
1680 * "(11) Typically, OpenGL specifies that if an error is generated by
1681 * a command, that command has no effect. This is somewhat
1682 * unfortunate for multi-bind commands, because it would require
1683 * a first pass to scan the entire list of bound objects for
1684 * errors and then a second pass to actually perform the
1685 * bindings. Should we have different error semantics?
1687 * RESOLVED: Yes. In this specification, when the parameters for
1688 * one of the <count> binding points are invalid, that binding
1689 * point is not updated and an error will be generated. However,
1690 * other binding points in the same command will be updated if
1691 * their parameters are valid and no other error occurs."
1694 _mesa_begin_bufferobj_lookups(ctx
);
1696 for (i
= 0; i
< count
; i
++) {
1697 struct gl_buffer_object
*vbo
;
1699 /* The ARB_multi_bind spec says:
1701 * "An INVALID_VALUE error is generated if any value in
1702 * <offsets> or <strides> is negative (per binding)."
1704 if (offsets
[i
] < 0) {
1705 _mesa_error(ctx
, GL_INVALID_VALUE
,
1706 "%s(offsets[%u]=%" PRId64
" < 0)",
1707 func
, i
, (int64_t) offsets
[i
]);
1711 if (strides
[i
] < 0) {
1712 _mesa_error(ctx
, GL_INVALID_VALUE
,
1713 "%s(strides[%u]=%d < 0)",
1714 func
, i
, strides
[i
]);
1718 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1719 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
1720 _mesa_error(ctx
, GL_INVALID_VALUE
,
1721 "%s(strides[%u]=%d > "
1722 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
1727 struct gl_vertex_buffer_binding
*binding
=
1728 &vao
->VertexBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1730 if (buffers
[i
] == binding
->BufferObj
->Name
)
1731 vbo
= binding
->BufferObj
;
1733 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
1738 vbo
= ctx
->Shared
->NullBufferObj
;
1741 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1742 vbo
, offsets
[i
], strides
[i
]);
1745 _mesa_end_bufferobj_lookups(ctx
);
1750 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1751 const GLintptr
*offsets
, const GLsizei
*strides
)
1753 GET_CURRENT_CONTEXT(ctx
);
1755 /* The ARB_vertex_attrib_binding spec says:
1757 * "An INVALID_OPERATION error is generated if no
1758 * vertex array object is bound."
1760 if (ctx
->API
== API_OPENGL_CORE
&&
1761 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1762 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1763 "glBindVertexBuffers(No array object bound)");
1767 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
1768 buffers
, offsets
, strides
,
1769 "glBindVertexBuffers");
1774 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
1775 const GLuint
*buffers
,
1776 const GLintptr
*offsets
, const GLsizei
*strides
)
1778 GET_CURRENT_CONTEXT(ctx
);
1779 struct gl_vertex_array_object
*vao
;
1781 /* The ARB_direct_state_access specification says:
1783 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1784 * if <vaobj> is not [compatibility profile: zero or] the name of an
1785 * existing vertex array object."
1787 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
1791 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
1792 buffers
, offsets
, strides
,
1793 "glVertexArrayVertexBuffers");
1798 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
1799 GLboolean normalized
, GLboolean integer
,
1800 GLboolean doubles
, GLbitfield legalTypes
,
1801 GLsizei maxSize
, GLuint relativeOffset
,
1804 GET_CURRENT_CONTEXT(ctx
);
1805 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1807 /* The ARB_vertex_attrib_binding spec says:
1809 * "An INVALID_OPERATION error is generated under any of the following
1811 * - if no vertex array object is currently bound (see section 2.10);
1814 * This error condition only applies to VertexAttribFormat and
1815 * VertexAttribIFormat in the extension spec, but we assume that this
1816 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
1817 * to all three functions.
1819 if (ctx
->API
== API_OPENGL_CORE
&&
1820 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1821 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1822 "%s(No array object bound)", func
);
1826 /* The ARB_vertex_attrib_binding spec says:
1828 * "The error INVALID_VALUE is generated if index is greater than or equal
1829 * to the value of MAX_VERTEX_ATTRIBS."
1831 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1832 _mesa_error(ctx
, GL_INVALID_VALUE
,
1833 "%s(attribindex=%u > "
1834 "GL_MAX_VERTEX_ATTRIBS)",
1839 FLUSH_VERTICES(ctx
, 0);
1841 update_array_format(ctx
, func
, ctx
->Array
.VAO
,
1842 VERT_ATTRIB_GENERIC(attribIndex
),
1843 legalTypes
, 1, maxSize
, size
, type
,
1844 normalized
, integer
, doubles
, relativeOffset
);
1849 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1850 GLboolean normalized
, GLuint relativeOffset
)
1852 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
1853 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
1854 BGRA_OR_4
, relativeOffset
,
1855 "glVertexAttribFormat");
1860 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1861 GLuint relativeOffset
)
1863 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
1864 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
1865 relativeOffset
, "glVertexAttribIFormat");
1870 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1871 GLuint relativeOffset
)
1873 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
1874 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
1875 relativeOffset
, "glVertexAttribLFormat");
1880 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
1881 GLenum type
, GLboolean normalized
,
1882 GLboolean integer
, GLboolean doubles
,
1883 GLbitfield legalTypes
, GLsizei maxSize
,
1884 GLuint relativeOffset
, const char *func
)
1886 GET_CURRENT_CONTEXT(ctx
);
1887 struct gl_vertex_array_object
*vao
;
1889 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1891 /* The ARB_direct_state_access spec says:
1893 * "An INVALID_OPERATION error is generated by VertexArrayAttrib*Format
1894 * if <vaobj> is not [compatibility profile: zero or] the name of an
1895 * existing vertex array object."
1897 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
1901 /* The ARB_vertex_attrib_binding spec says:
1903 * "The error INVALID_VALUE is generated if index is greater than or equal
1904 * to the value of MAX_VERTEX_ATTRIBS."
1906 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1907 _mesa_error(ctx
, GL_INVALID_VALUE
,
1908 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
1913 FLUSH_VERTICES(ctx
, 0);
1915 update_array_format(ctx
, func
, vao
,
1916 VERT_ATTRIB_GENERIC(attribIndex
),
1917 legalTypes
, 1, maxSize
, size
, type
, normalized
,
1918 integer
, doubles
, relativeOffset
);
1923 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
1924 GLenum type
, GLboolean normalized
,
1925 GLuint relativeOffset
)
1927 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
1928 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
1929 BGRA_OR_4
, relativeOffset
,
1930 "glVertexArrayAttribFormat");
1935 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
1936 GLint size
, GLenum type
,
1937 GLuint relativeOffset
)
1939 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
1940 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
1942 "glVertexArrayAttribIFormat");
1947 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
1948 GLint size
, GLenum type
,
1949 GLuint relativeOffset
)
1951 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
1952 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
1954 "glVertexArrayAttribLFormat");
1959 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
1961 GET_CURRENT_CONTEXT(ctx
);
1962 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1964 /* The ARB_vertex_attrib_binding spec says:
1966 * "An INVALID_OPERATION error is generated if no vertex array object
1969 if (ctx
->API
== API_OPENGL_CORE
&&
1970 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1971 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1972 "glVertexAttribBinding(No array object bound)");
1976 /* The ARB_vertex_attrib_binding spec says:
1978 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1979 * <bindingindex> must be less than the value of
1980 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1983 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1984 _mesa_error(ctx
, GL_INVALID_VALUE
,
1985 "glVertexAttribBinding(attribindex=%u >= "
1986 "GL_MAX_VERTEX_ATTRIBS)",
1991 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1992 _mesa_error(ctx
, GL_INVALID_VALUE
,
1993 "glVertexAttribBinding(bindingindex=%u >= "
1994 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1999 assert(VERT_ATTRIB_GENERIC(attribIndex
) <
2000 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
2002 vertex_attrib_binding(ctx
, VERT_ATTRIB_GENERIC(attribIndex
),
2003 VERT_ATTRIB_GENERIC(bindingIndex
));
2008 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2010 GET_CURRENT_CONTEXT(ctx
);
2011 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2013 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2014 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexBindingDivisor()");
2018 /* The ARB_vertex_attrib_binding spec says:
2020 * "An INVALID_OPERATION error is generated if no vertex array object
2023 if (ctx
->API
== API_OPENGL_CORE
&&
2024 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2025 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2026 "glVertexBindingDivisor(No array object bound)");
2030 /* The ARB_vertex_attrib_binding spec says:
2032 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2033 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2035 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2036 _mesa_error(ctx
, GL_INVALID_VALUE
,
2037 "glVertexBindingDivisor(bindingindex=%u > "
2038 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2043 vertex_binding_divisor(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2048 * Copy one client vertex array to another.
2051 _mesa_copy_client_array(struct gl_context
*ctx
,
2052 struct gl_client_array
*dst
,
2053 struct gl_client_array
*src
)
2055 dst
->Size
= src
->Size
;
2056 dst
->Type
= src
->Type
;
2057 dst
->Format
= src
->Format
;
2058 dst
->Stride
= src
->Stride
;
2059 dst
->StrideB
= src
->StrideB
;
2060 dst
->Ptr
= src
->Ptr
;
2061 dst
->Enabled
= src
->Enabled
;
2062 dst
->Normalized
= src
->Normalized
;
2063 dst
->Integer
= src
->Integer
;
2064 dst
->Doubles
= src
->Doubles
;
2065 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2066 dst
->_ElementSize
= src
->_ElementSize
;
2067 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2071 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2072 struct gl_vertex_attrib_array
*dst
,
2073 const struct gl_vertex_attrib_array
*src
)
2075 dst
->Size
= src
->Size
;
2076 dst
->Type
= src
->Type
;
2077 dst
->Format
= src
->Format
;
2078 dst
->VertexBinding
= src
->VertexBinding
;
2079 dst
->RelativeOffset
= src
->RelativeOffset
;
2080 dst
->Format
= src
->Format
;
2081 dst
->Integer
= src
->Integer
;
2082 dst
->Doubles
= src
->Doubles
;
2083 dst
->Normalized
= src
->Normalized
;
2084 dst
->Ptr
= src
->Ptr
;
2085 dst
->Enabled
= src
->Enabled
;
2086 dst
->_ElementSize
= src
->_ElementSize
;
2090 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2091 struct gl_vertex_buffer_binding
*dst
,
2092 const struct gl_vertex_buffer_binding
*src
)
2094 dst
->Offset
= src
->Offset
;
2095 dst
->Stride
= src
->Stride
;
2096 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2097 dst
->_BoundArrays
= src
->_BoundArrays
;
2099 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2103 * Print vertex array's fields.
2106 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
2109 fprintf(stderr
, " %s[%d]: ", name
, index
);
2111 fprintf(stderr
, " %s: ", name
);
2112 fprintf(stderr
, "Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
2113 array
->Ptr
, array
->Type
, array
->Size
,
2114 array
->_ElementSize
, array
->StrideB
,
2115 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
);
2120 * Print current vertex object/array info. For debug.
2123 _mesa_print_arrays(struct gl_context
*ctx
)
2125 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2128 printf("Array Object %u\n", vao
->Name
);
2129 if (vao
->_VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
2130 print_array("Vertex", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_POS
]);
2131 if (vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
2132 print_array("Normal", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
]);
2133 if (vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
2134 print_array("Color", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
]);
2135 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
2136 if (vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
2137 print_array("TexCoord", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
2138 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
2139 if (vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
2140 print_array("Attrib", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
2145 * Initialize vertex array state for given context.
2148 _mesa_init_varray(struct gl_context
*ctx
)
2150 ctx
->Array
.DefaultVAO
= ctx
->Driver
.NewArrayObject(ctx
, 0);
2151 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2152 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2154 ctx
->Array
.Objects
= _mesa_NewHashTable();
2159 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2162 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2164 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2165 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2166 _mesa_delete_vao(ctx
, vao
);
2171 * Free vertex array state for given context.
2174 _mesa_free_varray_data(struct gl_context
*ctx
)
2176 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2177 _mesa_DeleteHashTable(ctx
->Array
.Objects
);