2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
28 #include <inttypes.h> /* for PRId64 macro */
32 #include "bufferobj.h"
42 #include "main/dispatch.h"
45 /** Used to do error checking for GL_EXT_vertex_array_bgra */
49 /** Used to indicate which GL datatypes are accepted by each of the
50 * glVertex/Color/Attrib/EtcPointer() functions.
52 #define BOOL_BIT (1 << 0)
53 #define BYTE_BIT (1 << 1)
54 #define UNSIGNED_BYTE_BIT (1 << 2)
55 #define SHORT_BIT (1 << 3)
56 #define UNSIGNED_SHORT_BIT (1 << 4)
57 #define INT_BIT (1 << 5)
58 #define UNSIGNED_INT_BIT (1 << 6)
59 #define HALF_BIT (1 << 7)
60 #define FLOAT_BIT (1 << 8)
61 #define DOUBLE_BIT (1 << 9)
62 #define FIXED_ES_BIT (1 << 10)
63 #define FIXED_GL_BIT (1 << 11)
64 #define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12)
65 #define INT_2_10_10_10_REV_BIT (1 << 13)
66 #define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)
67 #define ALL_TYPE_BITS ((1 << 15) - 1)
69 #define ATTRIB_FORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
70 SHORT_BIT | UNSIGNED_SHORT_BIT | \
71 INT_BIT | UNSIGNED_INT_BIT | \
72 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | \
74 UNSIGNED_INT_2_10_10_10_REV_BIT | \
75 INT_2_10_10_10_REV_BIT | \
76 UNSIGNED_INT_10F_11F_11F_REV_BIT)
78 #define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
79 SHORT_BIT | UNSIGNED_SHORT_BIT | \
80 INT_BIT | UNSIGNED_INT_BIT)
82 #define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT
85 /** Convert GL datatype enum into a <type>_BIT value seen above */
87 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
94 case GL_UNSIGNED_BYTE
:
95 return UNSIGNED_BYTE_BIT
;
98 case GL_UNSIGNED_SHORT
:
99 return UNSIGNED_SHORT_BIT
;
102 case GL_UNSIGNED_INT
:
103 return UNSIGNED_INT_BIT
;
105 if (ctx
->Extensions
.ARB_half_float_vertex
)
114 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
115 case GL_UNSIGNED_INT_2_10_10_10_REV
:
116 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
117 case GL_INT_2_10_10_10_REV
:
118 return INT_2_10_10_10_REV_BIT
;
119 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
120 return UNSIGNED_INT_10F_11F_11F_REV_BIT
;
128 * Sets the VertexBinding field in the vertex attribute given by attribIndex.
131 vertex_attrib_binding(struct gl_context
*ctx
,
132 struct gl_vertex_array_object
*vao
,
136 struct gl_vertex_attrib_array
*array
= &vao
->VertexAttrib
[attribIndex
];
138 if (array
->VertexBinding
!= bindingIndex
) {
139 const GLbitfield64 array_bit
= VERT_BIT(attribIndex
);
141 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
143 vao
->VertexBinding
[array
->VertexBinding
]._BoundArrays
&= ~array_bit
;
144 vao
->VertexBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
146 array
->VertexBinding
= bindingIndex
;
148 vao
->NewArrays
|= array_bit
;
154 * Binds a buffer object to the vertex buffer binding point given by index,
155 * and sets the Offset and Stride fields.
158 bind_vertex_buffer(struct gl_context
*ctx
,
159 struct gl_vertex_array_object
*vao
,
161 struct gl_buffer_object
*vbo
,
162 GLintptr offset
, GLsizei stride
)
164 struct gl_vertex_buffer_binding
*binding
= &vao
->VertexBinding
[index
];
166 if (binding
->BufferObj
!= vbo
||
167 binding
->Offset
!= offset
||
168 binding
->Stride
!= stride
) {
170 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
172 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
174 binding
->Offset
= offset
;
175 binding
->Stride
= stride
;
177 vao
->NewArrays
|= binding
->_BoundArrays
;
183 * Sets the InstanceDivisor field in the vertex buffer binding point
184 * given by bindingIndex.
187 vertex_binding_divisor(struct gl_context
*ctx
,
188 struct gl_vertex_array_object
*vao
,
192 struct gl_vertex_buffer_binding
*binding
=
193 &vao
->VertexBinding
[bindingIndex
];
195 if (binding
->InstanceDivisor
!= divisor
) {
196 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
197 binding
->InstanceDivisor
= divisor
;
198 vao
->NewArrays
|= binding
->_BoundArrays
;
204 * Examine the API profile and extensions to determine which types are legal
205 * for vertex arrays. This is called once from update_array_format().
208 get_legal_types_mask(const struct gl_context
*ctx
)
210 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
212 if (_mesa_is_gles(ctx
)) {
213 legalTypesMask
&= ~(FIXED_GL_BIT
|
215 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
217 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
218 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
219 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
220 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
221 * quite as trivial as we'd like because it uses a different enum value
222 * for GL_HALF_FLOAT_OES.
224 if (ctx
->Version
< 30) {
225 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
227 UNSIGNED_INT_2_10_10_10_REV_BIT
|
228 INT_2_10_10_10_REV_BIT
|
233 legalTypesMask
&= ~FIXED_ES_BIT
;
235 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
236 legalTypesMask
&= ~FIXED_GL_BIT
;
238 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
239 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
240 INT_2_10_10_10_REV_BIT
);
242 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
243 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
246 return legalTypesMask
;
251 * Does error checking and updates the format in an attrib array.
253 * Called by update_array() and VertexAttrib*Format().
255 * \param func Name of calling function used for error reporting
256 * \param attrib The index of the attribute array
257 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
258 * \param sizeMin Min allowable size value
259 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
260 * \param size Components per element (1, 2, 3 or 4)
261 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
262 * \param normalized Whether integer types are converted to floats in [-1, 1]
263 * \param integer Integer-valued values (will not be normalized to [-1, 1])
264 * \param doubles Double values not reduced to floats
265 * \param relativeOffset Offset of the first element relative to the binding offset.
268 update_array_format(struct gl_context
*ctx
,
270 struct gl_vertex_array_object
*vao
,
271 GLuint attrib
, GLbitfield legalTypesMask
,
272 GLint sizeMin
, GLint sizeMax
,
273 GLint size
, GLenum type
,
274 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
275 GLuint relativeOffset
)
277 struct gl_vertex_attrib_array
*array
;
280 GLenum format
= GL_RGBA
;
282 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
283 /* Compute the LegalTypesMask only once, unless the context API has
284 * changed, in which case we want to compute it again. We can't do this
285 * in _mesa_init_varrays() below because extensions are not yet enabled
288 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
289 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
292 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
294 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
295 /* BGRA ordering is not supported in ES contexts.
300 typeBit
= type_to_bit(ctx
, type
);
301 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
302 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
303 func
, _mesa_lookup_enum_by_nr(type
));
307 /* Do size parameter checking.
308 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
309 * must be handled specially.
311 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
312 sizeMax
== BGRA_OR_4
&&
314 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
316 * "An INVALID_OPERATION error is generated under any of the following
319 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
320 * or UNSIGNED_INT_2_10_10_10_REV;
322 * • size is BGRA and normalized is FALSE;"
324 bool bgra_error
= false;
326 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
327 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
328 type
!= GL_INT_2_10_10_10_REV
&&
329 type
!= GL_UNSIGNED_BYTE
)
331 } else if (type
!= GL_UNSIGNED_BYTE
)
335 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
336 func
, _mesa_lookup_enum_by_nr(type
));
341 _mesa_error(ctx
, GL_INVALID_OPERATION
,
342 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
349 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
350 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
354 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
355 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
356 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
357 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
361 /* The ARB_vertex_attrib_binding_spec says:
363 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
364 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
366 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
367 _mesa_error(ctx
, GL_INVALID_VALUE
,
368 "%s(relativeOffset=%d > "
369 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
370 func
, relativeOffset
);
374 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
375 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
376 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
382 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
383 assert(elementSize
!= -1);
385 array
= &vao
->VertexAttrib
[attrib
];
388 array
->Format
= format
;
389 array
->Normalized
= normalized
;
390 array
->Integer
= integer
;
391 array
->Doubles
= doubles
;
392 array
->RelativeOffset
= relativeOffset
;
393 array
->_ElementSize
= elementSize
;
395 vao
->NewArrays
|= VERT_BIT(attrib
);
396 ctx
->NewState
|= _NEW_ARRAY
;
403 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
406 * \param func name of calling function used for error reporting
407 * \param attrib the attribute array index to update
408 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
409 * \param sizeMin min allowable size value
410 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
411 * \param size components per element (1, 2, 3 or 4)
412 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
413 * \param stride stride between elements, in elements
414 * \param normalized are integer types converted to floats in [-1, 1]?
415 * \param integer integer-valued values (will not be normalized to [-1,1])
416 * \param doubles Double values not reduced to floats
417 * \param ptr the address (or offset inside VBO) of the array data
420 update_array(struct gl_context
*ctx
,
422 GLuint attrib
, GLbitfield legalTypesMask
,
423 GLint sizeMin
, GLint sizeMax
,
424 GLint size
, GLenum type
, GLsizei stride
,
425 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
428 struct gl_vertex_attrib_array
*array
;
429 GLsizei effectiveStride
;
431 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
433 * "Client vertex arrays - all vertex array attribute pointers must
434 * refer to buffer objects (section 2.9.2). The default vertex array
435 * object (the name zero) is also deprecated. Calling
436 * VertexAttribPointer when no buffer object or no vertex array object
437 * is bound will generate an INVALID_OPERATION error..."
439 * The check for VBOs is handled below.
441 if (ctx
->API
== API_OPENGL_CORE
442 && (ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
)) {
443 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
449 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
453 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
454 stride
> ctx
->Const
.MaxVertexAttribStride
) {
455 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
456 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
460 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
462 * "An INVALID_OPERATION error is generated under any of the following
467 * * any of the *Pointer commands specifying the location and
468 * organization of vertex array data are called while zero is bound
469 * to the ARRAY_BUFFER buffer object binding point (see section
470 * 2.9.6), and the pointer argument is not NULL."
472 if (ptr
!= NULL
&& ctx
->Array
.VAO
->ARBsemantics
&&
473 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
474 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
478 if (!update_array_format(ctx
, func
, ctx
->Array
.VAO
, attrib
,
479 legalTypesMask
, sizeMin
, sizeMax
,
480 size
, type
, normalized
, integer
, doubles
, 0)) {
484 /* Reset the vertex attrib binding */
485 vertex_attrib_binding(ctx
, ctx
->Array
.VAO
, attrib
, attrib
);
487 /* The Stride and Ptr fields are not set by update_array_format() */
488 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
489 array
->Stride
= stride
;
490 array
->Ptr
= (const GLvoid
*) ptr
;
492 /* Update the vertex buffer binding */
493 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
494 bind_vertex_buffer(ctx
, ctx
->Array
.VAO
, attrib
, ctx
->Array
.ArrayBufferObj
,
495 (GLintptr
) ptr
, effectiveStride
);
500 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
502 GET_CURRENT_CONTEXT(ctx
);
503 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
504 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
505 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
506 DOUBLE_BIT
| HALF_BIT
|
507 UNSIGNED_INT_2_10_10_10_REV_BIT
|
508 INT_2_10_10_10_REV_BIT
);
510 FLUSH_VERTICES(ctx
, 0);
512 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
514 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
519 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
521 GET_CURRENT_CONTEXT(ctx
);
522 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
523 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
524 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
525 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
526 UNSIGNED_INT_2_10_10_10_REV_BIT
|
527 INT_2_10_10_10_REV_BIT
);
529 FLUSH_VERTICES(ctx
, 0);
531 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
533 3, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
538 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
540 GET_CURRENT_CONTEXT(ctx
);
541 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
542 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
543 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
544 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
545 INT_BIT
| UNSIGNED_INT_BIT
|
546 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
547 UNSIGNED_INT_2_10_10_10_REV_BIT
|
548 INT_2_10_10_10_REV_BIT
);
549 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
551 FLUSH_VERTICES(ctx
, 0);
553 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
554 legalTypes
, sizeMin
, BGRA_OR_4
,
555 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
560 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
562 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
563 GET_CURRENT_CONTEXT(ctx
);
565 FLUSH_VERTICES(ctx
, 0);
567 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
569 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
574 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
576 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
577 FLOAT_BIT
| DOUBLE_BIT
);
578 GET_CURRENT_CONTEXT(ctx
);
580 FLUSH_VERTICES(ctx
, 0);
582 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
584 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
589 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
590 GLsizei stride
, const GLvoid
*ptr
)
592 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
593 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
594 INT_BIT
| UNSIGNED_INT_BIT
|
595 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
596 UNSIGNED_INT_2_10_10_10_REV_BIT
|
597 INT_2_10_10_10_REV_BIT
);
598 GET_CURRENT_CONTEXT(ctx
);
600 FLUSH_VERTICES(ctx
, 0);
602 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
603 legalTypes
, 3, BGRA_OR_4
,
604 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
609 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
612 GET_CURRENT_CONTEXT(ctx
);
613 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
614 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
615 : (SHORT_BIT
| INT_BIT
|
616 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
617 UNSIGNED_INT_2_10_10_10_REV_BIT
|
618 INT_2_10_10_10_REV_BIT
);
619 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
620 const GLuint unit
= ctx
->Array
.ActiveTexture
;
622 FLUSH_VERTICES(ctx
, 0);
624 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
625 legalTypes
, sizeMin
, 4,
626 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
632 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
634 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
635 /* this is the same type that glEdgeFlag uses */
636 const GLboolean integer
= GL_FALSE
;
637 GET_CURRENT_CONTEXT(ctx
);
639 FLUSH_VERTICES(ctx
, 0);
641 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
643 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
648 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
650 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
651 GET_CURRENT_CONTEXT(ctx
);
653 FLUSH_VERTICES(ctx
, 0);
655 if (ctx
->API
!= API_OPENGLES
) {
656 _mesa_error(ctx
, GL_INVALID_OPERATION
,
657 "glPointSizePointer(ES 1.x only)");
661 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
663 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
668 * Set a generic vertex attribute array.
669 * Note that these arrays DO NOT alias the conventional GL vertex arrays
670 * (position, normal, color, fog, texcoord, etc).
673 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
674 GLboolean normalized
,
675 GLsizei stride
, const GLvoid
*ptr
)
677 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
678 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
679 INT_BIT
| UNSIGNED_INT_BIT
|
680 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
681 FIXED_ES_BIT
| FIXED_GL_BIT
|
682 UNSIGNED_INT_2_10_10_10_REV_BIT
|
683 INT_2_10_10_10_REV_BIT
|
684 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
685 GET_CURRENT_CONTEXT(ctx
);
687 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
688 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
692 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
693 legalTypes
, 1, BGRA_OR_4
,
694 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
699 * GL_EXT_gpu_shader4 / GL 3.0.
700 * Set an integer-valued vertex attribute array.
701 * Note that these arrays DO NOT alias the conventional GL vertex arrays
702 * (position, normal, color, fog, texcoord, etc).
705 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
706 GLsizei stride
, const GLvoid
*ptr
)
708 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
709 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
710 INT_BIT
| UNSIGNED_INT_BIT
);
711 const GLboolean normalized
= GL_FALSE
;
712 const GLboolean integer
= GL_TRUE
;
713 GET_CURRENT_CONTEXT(ctx
);
715 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
716 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
720 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
722 size
, type
, stride
, normalized
, integer
, GL_FALSE
, ptr
);
726 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
727 GLsizei stride
, const GLvoid
*ptr
)
729 GET_CURRENT_CONTEXT(ctx
);
730 const GLbitfield legalTypes
= (DOUBLE_BIT
);
731 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
732 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
736 update_array(ctx
, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index
),
738 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_TRUE
, ptr
);
743 enable_vertex_array_attrib(struct gl_context
*ctx
,
744 struct gl_vertex_array_object
*vao
,
748 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
749 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
753 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
755 if (!vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
756 /* was disabled, now being enabled */
757 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
758 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
759 vao
->_Enabled
|= VERT_BIT_GENERIC(index
);
760 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
766 _mesa_EnableVertexAttribArray(GLuint index
)
768 GET_CURRENT_CONTEXT(ctx
);
769 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
770 "glEnableVertexAttribArray");
775 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
777 GET_CURRENT_CONTEXT(ctx
);
778 struct gl_vertex_array_object
*vao
;
780 /* The ARB_direct_state_access specification says:
782 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
783 * and DisableVertexArrayAttrib if <vaobj> is not
784 * [compatibility profile: zero or] the name of an existing vertex
787 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
791 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
796 disable_vertex_array_attrib(struct gl_context
*ctx
,
797 struct gl_vertex_array_object
*vao
,
801 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
802 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
806 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
808 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
809 /* was enabled, now being disabled */
810 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
811 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
812 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
813 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
819 _mesa_DisableVertexAttribArray(GLuint index
)
821 GET_CURRENT_CONTEXT(ctx
);
822 disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
823 "glDisableVertexAttribArray");
828 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
830 GET_CURRENT_CONTEXT(ctx
);
831 struct gl_vertex_array_object
*vao
;
833 /* The ARB_direct_state_access specification says:
835 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
836 * and DisableVertexArrayAttrib if <vaobj> is not
837 * [compatibility profile: zero or] the name of an existing vertex
840 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
844 disable_vertex_array_attrib(ctx
, vao
, index
, "glDisableVertexArrayAttrib");
849 * Return info for a vertex attribute array (no alias with legacy
850 * vertex attributes (pos, normal, color, etc)). This function does
851 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
854 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
857 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
858 const struct gl_vertex_attrib_array
*array
;
860 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
861 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
865 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
867 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
870 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
871 return array
->Enabled
;
872 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
873 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
874 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
875 return array
->Stride
;
876 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
878 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
879 return array
->Normalized
;
880 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
881 return vao
->VertexBinding
[array
->VertexBinding
].BufferObj
->Name
;
882 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
883 if ((_mesa_is_desktop_gl(ctx
)
884 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
885 || _mesa_is_gles3(ctx
)) {
886 return array
->Integer
;
889 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
890 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
891 || _mesa_is_gles3(ctx
)) {
892 return vao
->VertexBinding
[array
->VertexBinding
].InstanceDivisor
;
895 case GL_VERTEX_ATTRIB_BINDING
:
896 if (_mesa_is_desktop_gl(ctx
)) {
897 return array
->VertexBinding
- VERT_ATTRIB_GENERIC0
;
900 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
901 if (_mesa_is_desktop_gl(ctx
)) {
902 return array
->RelativeOffset
;
910 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
915 static const GLfloat
*
916 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
919 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
920 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
924 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
925 _mesa_error(ctx
, GL_INVALID_VALUE
,
926 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
930 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
932 FLUSH_CURRENT(ctx
, 0);
933 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
937 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
939 GET_CURRENT_CONTEXT(ctx
);
941 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
942 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
948 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
949 "glGetVertexAttribfv");
955 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
957 GET_CURRENT_CONTEXT(ctx
);
959 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
960 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
962 params
[0] = (GLdouble
) v
[0];
963 params
[1] = (GLdouble
) v
[1];
964 params
[2] = (GLdouble
) v
[2];
965 params
[3] = (GLdouble
) v
[3];
969 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
970 "glGetVertexAttribdv");
975 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
977 GET_CURRENT_CONTEXT(ctx
);
979 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
980 const GLdouble
*v
= (const GLdouble
*)get_current_attrib(ctx
, index
, "glGetVertexAttribLdv");
989 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
990 "glGetVertexAttribLdv");
995 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
997 GET_CURRENT_CONTEXT(ctx
);
999 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1000 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1002 /* XXX should floats in[0,1] be scaled to full int range? */
1003 params
[0] = (GLint
) v
[0];
1004 params
[1] = (GLint
) v
[1];
1005 params
[2] = (GLint
) v
[2];
1006 params
[3] = (GLint
) v
[3];
1010 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
1011 "glGetVertexAttribiv");
1018 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1020 GET_CURRENT_CONTEXT(ctx
);
1022 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1023 const GLint
*v
= (const GLint
*)
1024 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1030 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
1031 "glGetVertexAttribIiv");
1038 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1040 GET_CURRENT_CONTEXT(ctx
);
1042 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1043 const GLuint
*v
= (const GLuint
*)
1044 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1050 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
1051 "glGetVertexAttribIuiv");
1057 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1059 GET_CURRENT_CONTEXT(ctx
);
1061 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1062 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1066 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1067 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1071 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1073 *pointer
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1078 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1079 GLsizei count
, const GLvoid
*ptr
)
1082 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1087 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1091 _mesa_NormalPointer(type
, stride
, ptr
);
1096 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1100 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1105 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1109 _mesa_IndexPointer(type
, stride
, ptr
);
1114 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1115 GLsizei count
, const GLvoid
*ptr
)
1118 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1123 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1126 _mesa_EdgeFlagPointer(stride
, ptr
);
1131 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1133 GET_CURRENT_CONTEXT(ctx
);
1134 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1135 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1136 GLenum ctype
= 0; /* color type */
1137 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1138 const GLint toffset
= 0; /* always zero */
1139 GLint defstride
; /* default stride */
1142 FLUSH_VERTICES(ctx
, 0);
1144 f
= sizeof(GLfloat
);
1145 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1148 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1154 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1155 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1160 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1161 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1166 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1167 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1168 ctype
= GL_UNSIGNED_BYTE
;
1171 defstride
= c
+ 2*f
;
1174 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1175 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1176 ctype
= GL_UNSIGNED_BYTE
;
1179 defstride
= c
+ 3*f
;
1182 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1183 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1190 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1191 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1196 case GL_C4F_N3F_V3F
:
1197 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1198 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1206 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1207 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1212 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1213 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1217 case GL_T2F_C4UB_V3F
:
1218 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1219 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1220 ctype
= GL_UNSIGNED_BYTE
;
1225 case GL_T2F_C3F_V3F
:
1226 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1227 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1233 case GL_T2F_N3F_V3F
:
1234 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1235 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1240 case GL_T2F_C4F_N3F_V3F
:
1241 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1242 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1249 case GL_T4F_C4F_N3F_V4F
:
1250 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1251 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1259 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1267 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1268 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1269 /* XXX also disable secondary color and generic arrays? */
1273 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1274 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1275 (GLubyte
*) pointer
+ toffset
);
1278 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1283 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1284 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1285 (GLubyte
*) pointer
+ coffset
);
1288 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1294 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1295 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1298 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1302 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1303 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1304 (GLubyte
*) pointer
+ voffset
);
1309 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1311 GET_CURRENT_CONTEXT(ctx
);
1313 FLUSH_VERTICES(ctx
, 0);
1315 if (MESA_VERBOSE
& VERBOSE_API
)
1316 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1319 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1323 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1326 if (ctx
->Array
.LockCount
!= 0) {
1327 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1331 ctx
->Array
.LockFirst
= first
;
1332 ctx
->Array
.LockCount
= count
;
1334 ctx
->NewState
|= _NEW_ARRAY
;
1339 _mesa_UnlockArraysEXT( void )
1341 GET_CURRENT_CONTEXT(ctx
);
1343 FLUSH_VERTICES(ctx
, 0);
1345 if (MESA_VERBOSE
& VERBOSE_API
)
1346 _mesa_debug(ctx
, "glUnlockArrays\n");
1348 if (ctx
->Array
.LockCount
== 0) {
1349 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1353 ctx
->Array
.LockFirst
= 0;
1354 ctx
->Array
.LockCount
= 0;
1355 ctx
->NewState
|= _NEW_ARRAY
;
1359 /* GL_EXT_multi_draw_arrays */
1361 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1362 const GLsizei
*count
, GLsizei primcount
)
1364 GET_CURRENT_CONTEXT(ctx
);
1367 FLUSH_VERTICES(ctx
, 0);
1369 for (i
= 0; i
< primcount
; i
++) {
1371 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1377 /* GL_IBM_multimode_draw_arrays */
1379 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1380 const GLsizei
* count
,
1381 GLsizei primcount
, GLint modestride
)
1383 GET_CURRENT_CONTEXT(ctx
);
1386 FLUSH_VERTICES(ctx
, 0);
1388 for ( i
= 0 ; i
< primcount
; i
++ ) {
1389 if ( count
[i
] > 0 ) {
1390 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1391 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1397 /* GL_IBM_multimode_draw_arrays */
1399 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1400 GLenum type
, const GLvoid
* const * indices
,
1401 GLsizei primcount
, GLint modestride
)
1403 GET_CURRENT_CONTEXT(ctx
);
1406 FLUSH_VERTICES(ctx
, 0);
1408 /* XXX not sure about ARB_vertex_buffer_object handling here */
1410 for ( i
= 0 ; i
< primcount
; i
++ ) {
1411 if ( count
[i
] > 0 ) {
1412 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1413 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1421 * GL_NV_primitive_restart and GL 3.1
1424 _mesa_PrimitiveRestartIndex(GLuint index
)
1426 GET_CURRENT_CONTEXT(ctx
);
1428 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1429 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1433 if (ctx
->Array
.RestartIndex
!= index
) {
1434 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1435 ctx
->Array
.RestartIndex
= index
;
1441 * See GL_ARB_instanced_arrays.
1442 * Note that the instance divisor only applies to generic arrays, not
1443 * the legacy vertex arrays.
1446 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1448 GET_CURRENT_CONTEXT(ctx
);
1450 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1451 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1453 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1454 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1458 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1459 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1464 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
1466 /* The ARB_vertex_attrib_binding spec says:
1470 * void VertexAttribDivisor(uint index, uint divisor);
1472 * is equivalent to (assuming no errors are generated):
1474 * VertexAttribBinding(index, index);
1475 * VertexBindingDivisor(index, divisor);"
1477 vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
1478 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
1483 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1485 /* From the OpenGL 4.3 core specification, page 302:
1486 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1487 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1490 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1492 case GL_UNSIGNED_BYTE
:
1494 case GL_UNSIGNED_SHORT
:
1496 case GL_UNSIGNED_INT
:
1499 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1503 return ctx
->Array
.RestartIndex
;
1508 * GL_ARB_vertex_attrib_binding
1511 vertex_array_vertex_buffer(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
,
1512 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1513 GLsizei stride
, const char *func
)
1515 struct gl_buffer_object
*vbo
;
1517 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1519 /* The ARB_vertex_attrib_binding spec says:
1521 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1522 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1524 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1525 _mesa_error(ctx
, GL_INVALID_VALUE
,
1526 "%s(bindingindex=%u > "
1527 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1528 func
, bindingIndex
);
1532 /* The ARB_vertex_attrib_binding spec says:
1534 * "The error INVALID_VALUE is generated if <stride> or <offset>
1538 _mesa_error(ctx
, GL_INVALID_VALUE
,
1539 "%s(offset=%" PRId64
" < 0)",
1540 func
, (int64_t) offset
);
1545 _mesa_error(ctx
, GL_INVALID_VALUE
,
1546 "%s(stride=%d < 0)", func
, stride
);
1550 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1551 stride
> ctx
->Const
.MaxVertexAttribStride
) {
1552 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
1553 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
1557 if (buffer
== vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1558 vbo
= vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1559 } else if (buffer
!= 0) {
1560 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1562 /* From the GL_ARB_vertex_attrib_array spec:
1564 * "[Core profile only:]
1565 * An INVALID_OPERATION error is generated if buffer is not zero or a
1566 * name returned from a previous call to GenBuffers, or if such a name
1567 * has since been deleted with DeleteBuffers.
1569 * Otherwise, we fall back to the same compat profile behavior as other
1570 * object references (automatically gen it).
1572 if (!_mesa_handle_bind_buffer_gen(ctx
, GL_ARRAY_BUFFER
, buffer
,
1576 /* The ARB_vertex_attrib_binding spec says:
1578 * "If <buffer> is zero, any buffer object attached to this
1579 * bindpoint is detached."
1581 vbo
= ctx
->Shared
->NullBufferObj
;
1584 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
1585 vbo
, offset
, stride
);
1590 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1593 GET_CURRENT_CONTEXT(ctx
);
1595 /* The ARB_vertex_attrib_binding spec says:
1597 * "An INVALID_OPERATION error is generated if no vertex array object
1600 if (ctx
->API
== API_OPENGL_CORE
&&
1601 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1602 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1603 "glBindVertexBuffer(No array object bound)");
1607 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
1608 buffer
, offset
, stride
, "glBindVertexBuffer");
1613 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
1614 GLintptr offset
, GLsizei stride
)
1616 GET_CURRENT_CONTEXT(ctx
);
1617 struct gl_vertex_array_object
*vao
;
1619 /* The ARB_direct_state_access specification says:
1621 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1622 * if <vaobj> is not [compatibility profile: zero or] the name of an
1623 * existing vertex array object."
1625 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
1629 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
,
1630 buffer
, offset
, stride
,
1631 "glVertexArrayVertexBuffer");
1636 vertex_array_vertex_buffers(struct gl_context
*ctx
,
1637 struct gl_vertex_array_object
*vao
,
1638 GLuint first
, GLsizei count
, const GLuint
*buffers
,
1639 const GLintptr
*offsets
, const GLsizei
*strides
,
1644 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1646 /* The ARB_multi_bind spec says:
1648 * "An INVALID_OPERATION error is generated if <first> + <count>
1649 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1651 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1652 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1653 "%s(first=%u + count=%d > the value of "
1654 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1655 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1661 * The ARB_multi_bind spec says:
1663 * "If <buffers> is NULL, each affected vertex buffer binding point
1664 * from <first> through <first>+<count>-1 will be reset to have no
1665 * bound buffer object. In this case, the offsets and strides
1666 * associated with the binding points are set to default values,
1667 * ignoring <offsets> and <strides>."
1669 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1671 for (i
= 0; i
< count
; i
++)
1672 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1678 /* Note that the error semantics for multi-bind commands differ from
1679 * those of other GL commands.
1681 * The Issues section in the ARB_multi_bind spec says:
1683 * "(11) Typically, OpenGL specifies that if an error is generated by
1684 * a command, that command has no effect. This is somewhat
1685 * unfortunate for multi-bind commands, because it would require
1686 * a first pass to scan the entire list of bound objects for
1687 * errors and then a second pass to actually perform the
1688 * bindings. Should we have different error semantics?
1690 * RESOLVED: Yes. In this specification, when the parameters for
1691 * one of the <count> binding points are invalid, that binding
1692 * point is not updated and an error will be generated. However,
1693 * other binding points in the same command will be updated if
1694 * their parameters are valid and no other error occurs."
1697 _mesa_begin_bufferobj_lookups(ctx
);
1699 for (i
= 0; i
< count
; i
++) {
1700 struct gl_buffer_object
*vbo
;
1702 /* The ARB_multi_bind spec says:
1704 * "An INVALID_VALUE error is generated if any value in
1705 * <offsets> or <strides> is negative (per binding)."
1707 if (offsets
[i
] < 0) {
1708 _mesa_error(ctx
, GL_INVALID_VALUE
,
1709 "%s(offsets[%u]=%" PRId64
" < 0)",
1710 func
, i
, (int64_t) offsets
[i
]);
1714 if (strides
[i
] < 0) {
1715 _mesa_error(ctx
, GL_INVALID_VALUE
,
1716 "%s(strides[%u]=%d < 0)",
1717 func
, i
, strides
[i
]);
1721 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1722 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
1723 _mesa_error(ctx
, GL_INVALID_VALUE
,
1724 "%s(strides[%u]=%d > "
1725 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
1730 struct gl_vertex_buffer_binding
*binding
=
1731 &vao
->VertexBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1733 if (buffers
[i
] == binding
->BufferObj
->Name
)
1734 vbo
= binding
->BufferObj
;
1736 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
1741 vbo
= ctx
->Shared
->NullBufferObj
;
1744 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1745 vbo
, offsets
[i
], strides
[i
]);
1748 _mesa_end_bufferobj_lookups(ctx
);
1753 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1754 const GLintptr
*offsets
, const GLsizei
*strides
)
1756 GET_CURRENT_CONTEXT(ctx
);
1758 /* The ARB_vertex_attrib_binding spec says:
1760 * "An INVALID_OPERATION error is generated if no
1761 * vertex array object is bound."
1763 if (ctx
->API
== API_OPENGL_CORE
&&
1764 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1765 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1766 "glBindVertexBuffers(No array object bound)");
1770 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
1771 buffers
, offsets
, strides
,
1772 "glBindVertexBuffers");
1777 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
1778 const GLuint
*buffers
,
1779 const GLintptr
*offsets
, const GLsizei
*strides
)
1781 GET_CURRENT_CONTEXT(ctx
);
1782 struct gl_vertex_array_object
*vao
;
1784 /* The ARB_direct_state_access specification says:
1786 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1787 * if <vaobj> is not [compatibility profile: zero or] the name of an
1788 * existing vertex array object."
1790 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
1794 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
1795 buffers
, offsets
, strides
,
1796 "glVertexArrayVertexBuffers");
1801 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
1802 GLboolean normalized
, GLboolean integer
,
1803 GLboolean doubles
, GLbitfield legalTypes
,
1804 GLsizei maxSize
, GLuint relativeOffset
,
1807 GET_CURRENT_CONTEXT(ctx
);
1808 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1810 /* The ARB_vertex_attrib_binding spec says:
1812 * "An INVALID_OPERATION error is generated under any of the following
1814 * - if no vertex array object is currently bound (see section 2.10);
1817 * This error condition only applies to VertexAttribFormat and
1818 * VertexAttribIFormat in the extension spec, but we assume that this
1819 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
1820 * to all three functions.
1822 if (ctx
->API
== API_OPENGL_CORE
&&
1823 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1824 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1825 "%s(No array object bound)", func
);
1829 /* The ARB_vertex_attrib_binding spec says:
1831 * "The error INVALID_VALUE is generated if index is greater than or equal
1832 * to the value of MAX_VERTEX_ATTRIBS."
1834 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1835 _mesa_error(ctx
, GL_INVALID_VALUE
,
1836 "%s(attribindex=%u > "
1837 "GL_MAX_VERTEX_ATTRIBS)",
1842 FLUSH_VERTICES(ctx
, 0);
1844 update_array_format(ctx
, func
, ctx
->Array
.VAO
,
1845 VERT_ATTRIB_GENERIC(attribIndex
),
1846 legalTypes
, 1, maxSize
, size
, type
,
1847 normalized
, integer
, doubles
, relativeOffset
);
1852 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1853 GLboolean normalized
, GLuint relativeOffset
)
1855 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
1856 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
1857 BGRA_OR_4
, relativeOffset
,
1858 "glVertexAttribFormat");
1863 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1864 GLuint relativeOffset
)
1866 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
1867 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
1868 relativeOffset
, "glVertexAttribIFormat");
1873 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1874 GLuint relativeOffset
)
1876 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
1877 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
1878 relativeOffset
, "glVertexAttribLFormat");
1883 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
1884 GLenum type
, GLboolean normalized
,
1885 GLboolean integer
, GLboolean doubles
,
1886 GLbitfield legalTypes
, GLsizei maxSize
,
1887 GLuint relativeOffset
, const char *func
)
1889 GET_CURRENT_CONTEXT(ctx
);
1890 struct gl_vertex_array_object
*vao
;
1892 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1894 /* The ARB_direct_state_access spec says:
1896 * "An INVALID_OPERATION error is generated by VertexArrayAttrib*Format
1897 * if <vaobj> is not [compatibility profile: zero or] the name of an
1898 * existing vertex array object."
1900 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
1904 /* The ARB_vertex_attrib_binding spec says:
1906 * "The error INVALID_VALUE is generated if index is greater than or equal
1907 * to the value of MAX_VERTEX_ATTRIBS."
1909 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1910 _mesa_error(ctx
, GL_INVALID_VALUE
,
1911 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
1916 FLUSH_VERTICES(ctx
, 0);
1918 update_array_format(ctx
, func
, vao
,
1919 VERT_ATTRIB_GENERIC(attribIndex
),
1920 legalTypes
, 1, maxSize
, size
, type
, normalized
,
1921 integer
, doubles
, relativeOffset
);
1926 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
1927 GLenum type
, GLboolean normalized
,
1928 GLuint relativeOffset
)
1930 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
1931 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
1932 BGRA_OR_4
, relativeOffset
,
1933 "glVertexArrayAttribFormat");
1938 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
1939 GLint size
, GLenum type
,
1940 GLuint relativeOffset
)
1942 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
1943 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
1945 "glVertexArrayAttribIFormat");
1950 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
1951 GLint size
, GLenum type
,
1952 GLuint relativeOffset
)
1954 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
1955 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
1957 "glVertexArrayAttribLFormat");
1962 vertex_array_attrib_binding(struct gl_context
*ctx
,
1963 struct gl_vertex_array_object
*vao
,
1964 GLuint attribIndex
, GLuint bindingIndex
,
1967 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1969 /* The ARB_vertex_attrib_binding spec says:
1971 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1972 * <bindingindex> must be less than the value of
1973 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1976 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1977 _mesa_error(ctx
, GL_INVALID_VALUE
,
1978 "%s(attribindex=%u >= "
1979 "GL_MAX_VERTEX_ATTRIBS)",
1984 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1985 _mesa_error(ctx
, GL_INVALID_VALUE
,
1986 "%s(bindingindex=%u >= "
1987 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1988 func
, bindingIndex
);
1992 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
1994 vertex_attrib_binding(ctx
, vao
,
1995 VERT_ATTRIB_GENERIC(attribIndex
),
1996 VERT_ATTRIB_GENERIC(bindingIndex
));
2001 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2003 GET_CURRENT_CONTEXT(ctx
);
2005 /* The ARB_vertex_attrib_binding spec says:
2007 * "An INVALID_OPERATION error is generated if no vertex array object
2010 if (ctx
->API
== API_OPENGL_CORE
&&
2011 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2012 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2013 "glVertexAttribBinding(No array object bound)");
2017 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2018 attribIndex
, bindingIndex
,
2019 "glVertexAttribBinding");
2024 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2026 GET_CURRENT_CONTEXT(ctx
);
2027 struct gl_vertex_array_object
*vao
;
2029 /* The ARB_direct_state_access specification says:
2031 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2032 * if <vaobj> is not [compatibility profile: zero or] the name of an
2033 * existing vertex array object."
2035 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2039 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2040 "glVertexArrayAttribBinding");
2045 vertex_array_binding_divisor(struct gl_context
*ctx
,
2046 struct gl_vertex_array_object
*vao
,
2047 GLuint bindingIndex
, GLuint divisor
,
2050 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2052 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2053 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
2057 /* The ARB_vertex_attrib_binding spec says:
2059 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2060 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2062 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2063 _mesa_error(ctx
, GL_INVALID_VALUE
,
2064 "%s(bindingindex=%u > "
2065 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2066 func
, bindingIndex
);
2070 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2075 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2077 GET_CURRENT_CONTEXT(ctx
);
2079 /* The ARB_vertex_attrib_binding spec says:
2081 * "An INVALID_OPERATION error is generated if no vertex array object
2084 if (ctx
->API
== API_OPENGL_CORE
&&
2085 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2086 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2087 "glVertexBindingDivisor(No array object bound)");
2091 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
2092 bindingIndex
, divisor
,
2093 "glVertexBindingDivisor");
2098 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
, GLuint divisor
)
2100 struct gl_vertex_array_object
*vao
;
2101 GET_CURRENT_CONTEXT(ctx
);
2103 /* The ARB_direct_state_access specification says:
2105 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2106 * if <vaobj> is not [compatibility profile: zero or] the name of an
2107 * existing vertex array object."
2109 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayBindingDivisor");
2113 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
2114 "glVertexArrayBindingDivisor");
2119 * Copy one client vertex array to another.
2122 _mesa_copy_client_array(struct gl_context
*ctx
,
2123 struct gl_client_array
*dst
,
2124 struct gl_client_array
*src
)
2126 dst
->Size
= src
->Size
;
2127 dst
->Type
= src
->Type
;
2128 dst
->Format
= src
->Format
;
2129 dst
->Stride
= src
->Stride
;
2130 dst
->StrideB
= src
->StrideB
;
2131 dst
->Ptr
= src
->Ptr
;
2132 dst
->Enabled
= src
->Enabled
;
2133 dst
->Normalized
= src
->Normalized
;
2134 dst
->Integer
= src
->Integer
;
2135 dst
->Doubles
= src
->Doubles
;
2136 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2137 dst
->_ElementSize
= src
->_ElementSize
;
2138 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2142 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2143 struct gl_vertex_attrib_array
*dst
,
2144 const struct gl_vertex_attrib_array
*src
)
2146 dst
->Size
= src
->Size
;
2147 dst
->Type
= src
->Type
;
2148 dst
->Format
= src
->Format
;
2149 dst
->VertexBinding
= src
->VertexBinding
;
2150 dst
->RelativeOffset
= src
->RelativeOffset
;
2151 dst
->Format
= src
->Format
;
2152 dst
->Integer
= src
->Integer
;
2153 dst
->Doubles
= src
->Doubles
;
2154 dst
->Normalized
= src
->Normalized
;
2155 dst
->Ptr
= src
->Ptr
;
2156 dst
->Enabled
= src
->Enabled
;
2157 dst
->_ElementSize
= src
->_ElementSize
;
2161 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2162 struct gl_vertex_buffer_binding
*dst
,
2163 const struct gl_vertex_buffer_binding
*src
)
2165 dst
->Offset
= src
->Offset
;
2166 dst
->Stride
= src
->Stride
;
2167 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2168 dst
->_BoundArrays
= src
->_BoundArrays
;
2170 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2174 * Print vertex array's fields.
2177 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
2180 fprintf(stderr
, " %s[%d]: ", name
, index
);
2182 fprintf(stderr
, " %s: ", name
);
2183 fprintf(stderr
, "Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
2184 array
->Ptr
, array
->Type
, array
->Size
,
2185 array
->_ElementSize
, array
->StrideB
,
2186 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
);
2191 * Print current vertex object/array info. For debug.
2194 _mesa_print_arrays(struct gl_context
*ctx
)
2196 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2199 printf("Array Object %u\n", vao
->Name
);
2200 if (vao
->_VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
2201 print_array("Vertex", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_POS
]);
2202 if (vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
2203 print_array("Normal", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
]);
2204 if (vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
2205 print_array("Color", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
]);
2206 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
2207 if (vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
2208 print_array("TexCoord", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
2209 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
2210 if (vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
2211 print_array("Attrib", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
2216 * Initialize vertex array state for given context.
2219 _mesa_init_varray(struct gl_context
*ctx
)
2221 ctx
->Array
.DefaultVAO
= ctx
->Driver
.NewArrayObject(ctx
, 0);
2222 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2223 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2225 ctx
->Array
.Objects
= _mesa_NewHashTable();
2230 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2233 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2235 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2236 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2237 _mesa_delete_vao(ctx
, vao
);
2242 * Free vertex array state for given context.
2245 _mesa_free_varray_data(struct gl_context
*ctx
)
2247 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2248 _mesa_DeleteHashTable(ctx
->Array
.Objects
);