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 case GL_HALF_FLOAT_OES
:
106 if (ctx
->Extensions
.ARB_half_float_vertex
)
115 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
116 case GL_UNSIGNED_INT_2_10_10_10_REV
:
117 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
118 case GL_INT_2_10_10_10_REV
:
119 return INT_2_10_10_10_REV_BIT
;
120 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
121 return UNSIGNED_INT_10F_11F_11F_REV_BIT
;
129 * Depending on the position and generic0 attributes enable flags select
130 * the one that is used for both attributes.
131 * The generic0 attribute takes precedence.
134 update_attribute_map_mode(const struct gl_context
*ctx
,
135 struct gl_vertex_array_object
*vao
)
138 * There is no need to change the mapping away from the
139 * identity mapping if we are not in compat mode.
141 if (ctx
->API
!= API_OPENGL_COMPAT
)
143 /* The generic0 attribute superseeds the position attribute */
144 const GLbitfield enabled
= vao
->_Enabled
;
145 if (enabled
& VERT_BIT_GENERIC0
)
146 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_GENERIC0
;
147 else if (enabled
& VERT_BIT_POS
)
148 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_POSITION
;
150 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_IDENTITY
;
155 * Sets the BufferBindingIndex field for the vertex attribute given by
159 _mesa_vertex_attrib_binding(struct gl_context
*ctx
,
160 struct gl_vertex_array_object
*vao
,
161 gl_vert_attrib attribIndex
,
162 GLuint bindingIndex
, bool flush_vertices
)
164 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attribIndex
];
166 if (array
->BufferBindingIndex
!= bindingIndex
) {
167 const GLbitfield array_bit
= VERT_BIT(attribIndex
);
169 if (_mesa_is_bufferobj(vao
->BufferBinding
[bindingIndex
].BufferObj
))
170 vao
->VertexAttribBufferMask
|= array_bit
;
172 vao
->VertexAttribBufferMask
&= ~array_bit
;
174 if (flush_vertices
) {
175 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
178 vao
->BufferBinding
[array
->BufferBindingIndex
]._BoundArrays
&= ~array_bit
;
179 vao
->BufferBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
181 array
->BufferBindingIndex
= bindingIndex
;
183 vao
->NewArrays
|= vao
->_Enabled
& array_bit
;
189 * Binds a buffer object to the vertex buffer binding point given by index,
190 * and sets the Offset and Stride fields.
193 _mesa_bind_vertex_buffer(struct gl_context
*ctx
,
194 struct gl_vertex_array_object
*vao
,
196 struct gl_buffer_object
*vbo
,
197 GLintptr offset
, GLsizei stride
, bool flush_vertices
)
199 assert(index
< ARRAY_SIZE(vao
->BufferBinding
));
200 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
202 if (binding
->BufferObj
!= vbo
||
203 binding
->Offset
!= offset
||
204 binding
->Stride
!= stride
) {
205 if (flush_vertices
) {
206 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
209 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
211 binding
->Offset
= offset
;
212 binding
->Stride
= stride
;
214 if (!_mesa_is_bufferobj(vbo
))
215 vao
->VertexAttribBufferMask
&= ~binding
->_BoundArrays
;
217 vao
->VertexAttribBufferMask
|= binding
->_BoundArrays
;
219 vao
->NewArrays
|= vao
->_Enabled
& binding
->_BoundArrays
;
225 * Sets the InstanceDivisor field in the vertex buffer binding point
226 * given by bindingIndex.
229 vertex_binding_divisor(struct gl_context
*ctx
,
230 struct gl_vertex_array_object
*vao
,
234 struct gl_vertex_buffer_binding
*binding
=
235 &vao
->BufferBinding
[bindingIndex
];
237 if (binding
->InstanceDivisor
!= divisor
) {
238 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
239 binding
->InstanceDivisor
= divisor
;
240 vao
->NewArrays
|= vao
->_Enabled
& binding
->_BoundArrays
;
246 * Examine the API profile and extensions to determine which types are legal
247 * for vertex arrays. This is called once from update_array_format().
250 get_legal_types_mask(const struct gl_context
*ctx
)
252 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
254 if (_mesa_is_gles(ctx
)) {
255 legalTypesMask
&= ~(FIXED_GL_BIT
|
257 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
259 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
260 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
261 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
262 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
263 * quite as trivial as we'd like because it uses a different enum value
264 * for GL_HALF_FLOAT_OES.
266 if (ctx
->Version
< 30) {
267 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
269 UNSIGNED_INT_2_10_10_10_REV_BIT
|
270 INT_2_10_10_10_REV_BIT
);
272 if (!_mesa_has_OES_vertex_half_float(ctx
))
273 legalTypesMask
&= ~HALF_BIT
;
277 legalTypesMask
&= ~FIXED_ES_BIT
;
279 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
280 legalTypesMask
&= ~FIXED_GL_BIT
;
282 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
283 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
284 INT_2_10_10_10_REV_BIT
);
286 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
287 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
290 return legalTypesMask
;
294 get_array_format(const struct gl_context
*ctx
, GLint sizeMax
, GLint
*size
)
296 GLenum format
= GL_RGBA
;
298 /* Do size parameter checking.
299 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
300 * must be handled specially.
302 if (ctx
->Extensions
.EXT_vertex_array_bgra
&& sizeMax
== BGRA_OR_4
&&
313 * \param attrib The index of the attribute array
314 * \param size Components per element (1, 2, 3 or 4)
315 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
316 * \param format Either GL_RGBA or GL_BGRA.
317 * \param normalized Whether integer types are converted to floats in [-1, 1]
318 * \param integer Integer-valued values (will not be normalized to [-1, 1])
319 * \param doubles Double values not reduced to floats
320 * \param relativeOffset Offset of the first element relative to the binding
322 * \param flush_verties Should \c FLUSH_VERTICES be invoked before updating
326 _mesa_update_array_format(struct gl_context
*ctx
,
327 struct gl_vertex_array_object
*vao
,
328 gl_vert_attrib attrib
, GLint size
, GLenum type
,
329 GLenum format
, GLboolean normalized
,
330 GLboolean integer
, GLboolean doubles
,
331 GLuint relativeOffset
)
333 struct gl_array_attributes
*const array
= &vao
->VertexAttrib
[attrib
];
338 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
339 assert(elementSize
!= -1);
343 array
->Format
= format
;
344 array
->Normalized
= normalized
;
345 array
->Integer
= integer
;
346 array
->Doubles
= doubles
;
347 array
->RelativeOffset
= relativeOffset
;
348 array
->_ElementSize
= elementSize
;
350 vao
->NewArrays
|= vao
->_Enabled
& VERT_BIT(attrib
);
351 ctx
->NewState
|= _NEW_ARRAY
;
355 * Does error checking of the format in an attrib array.
357 * Called by *Pointer() and VertexAttrib*Format().
359 * \param func Name of calling function used for error reporting
360 * \param attrib The index of the attribute array
361 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
362 * \param sizeMin Min allowable size value
363 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
364 * \param size Components per element (1, 2, 3 or 4)
365 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
366 * \param normalized Whether integer types are converted to floats in [-1, 1]
367 * \param integer Integer-valued values (will not be normalized to [-1, 1])
368 * \param doubles Double values not reduced to floats
369 * \param relativeOffset Offset of the first element relative to the binding offset.
370 * \return bool True if validation is successful, False otherwise.
373 validate_array_format(struct gl_context
*ctx
, const char *func
,
374 struct gl_vertex_array_object
*vao
,
375 GLuint attrib
, GLbitfield legalTypesMask
,
376 GLint sizeMin
, GLint sizeMax
,
377 GLint size
, GLenum type
, GLboolean normalized
,
378 GLboolean integer
, GLboolean doubles
,
379 GLuint relativeOffset
, GLenum format
)
383 /* at most, one of these bools can be true */
384 assert((int) normalized
+ (int) integer
+ (int) doubles
<= 1);
386 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
387 /* Compute the LegalTypesMask only once, unless the context API has
388 * changed, in which case we want to compute it again. We can't do this
389 * in _mesa_init_varrays() below because extensions are not yet enabled
392 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
393 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
396 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
398 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
399 /* BGRA ordering is not supported in ES contexts.
404 typeBit
= type_to_bit(ctx
, type
);
405 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
406 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
407 func
, _mesa_enum_to_string(type
));
411 if (format
== GL_BGRA
) {
412 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
414 * "An INVALID_OPERATION error is generated under any of the following
417 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
418 * or UNSIGNED_INT_2_10_10_10_REV;
420 * • size is BGRA and normalized is FALSE;"
422 bool bgra_error
= false;
424 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
425 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
426 type
!= GL_INT_2_10_10_10_REV
&&
427 type
!= GL_UNSIGNED_BYTE
)
429 } else if (type
!= GL_UNSIGNED_BYTE
)
433 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
434 func
, _mesa_enum_to_string(type
));
439 _mesa_error(ctx
, GL_INVALID_OPERATION
,
440 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
444 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
445 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
449 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
450 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
451 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
452 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
456 /* The ARB_vertex_attrib_binding_spec says:
458 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
459 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
461 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
462 _mesa_error(ctx
, GL_INVALID_VALUE
,
463 "%s(relativeOffset=%d > "
464 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
465 func
, relativeOffset
);
469 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
470 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
471 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
479 * Do error checking for glVertex/Color/TexCoord/...Pointer functions.
481 * \param func name of calling function used for error reporting
482 * \param attrib the attribute array index to update
483 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
484 * \param sizeMin min allowable size value
485 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
486 * \param size components per element (1, 2, 3 or 4)
487 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
488 * \param stride stride between elements, in elements
489 * \param normalized are integer types converted to floats in [-1, 1]?
490 * \param integer integer-valued values (will not be normalized to [-1,1])
491 * \param doubles Double values not reduced to floats
492 * \param ptr the address (or offset inside VBO) of the array data
495 validate_array(struct gl_context
*ctx
, const char *func
,
496 GLuint attrib
, GLbitfield legalTypesMask
,
497 GLint sizeMin
, GLint sizeMax
,
498 GLint size
, GLenum type
, GLsizei stride
,
499 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
502 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
504 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
506 * "Client vertex arrays - all vertex array attribute pointers must
507 * refer to buffer objects (section 2.9.2). The default vertex array
508 * object (the name zero) is also deprecated. Calling
509 * VertexAttribPointer when no buffer object or no vertex array object
510 * is bound will generate an INVALID_OPERATION error..."
512 * The check for VBOs is handled below.
514 if (ctx
->API
== API_OPENGL_CORE
&& (vao
== ctx
->Array
.DefaultVAO
)) {
515 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
521 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
525 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44 &&
526 stride
> ctx
->Const
.MaxVertexAttribStride
) {
527 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
528 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
532 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
534 * "An INVALID_OPERATION error is generated under any of the following
539 * * any of the *Pointer commands specifying the location and
540 * organization of vertex array data are called while zero is bound
541 * to the ARRAY_BUFFER buffer object binding point (see section
542 * 2.9.6), and the pointer argument is not NULL."
544 if (ptr
!= NULL
&& vao
!= ctx
->Array
.DefaultVAO
&&
545 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
546 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
553 validate_array_and_format(struct gl_context
*ctx
, const char *func
,
554 GLuint attrib
, GLbitfield legalTypes
,
555 GLint sizeMin
, GLint sizeMax
,
556 GLint size
, GLenum type
, GLsizei stride
,
557 GLboolean normalized
, GLboolean integer
,
558 GLboolean doubles
, GLenum format
, const GLvoid
*ptr
,
559 struct gl_vertex_array_object
*vao
)
561 validate_array(ctx
, func
, attrib
, legalTypes
, sizeMin
, sizeMax
, size
,
562 type
, stride
, normalized
, integer
, doubles
, ptr
);
564 return validate_array_format(ctx
, func
, vao
, attrib
, legalTypes
, sizeMin
,
565 sizeMax
, size
, type
, normalized
, integer
,
571 * Update state for glVertex/Color/TexCoord/...Pointer functions.
573 * \param attrib the attribute array index to update
574 * \param format Either GL_RGBA or GL_BGRA.
575 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
576 * \param size components per element (1, 2, 3 or 4)
577 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
578 * \param stride stride between elements, in elements
579 * \param normalized are integer types converted to floats in [-1, 1]?
580 * \param integer integer-valued values (will not be normalized to [-1,1])
581 * \param doubles Double values not reduced to floats
582 * \param ptr the address (or offset inside VBO) of the array data
585 update_array(struct gl_context
*ctx
,
586 GLuint attrib
, GLenum format
,
588 GLint size
, GLenum type
, GLsizei stride
,
589 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
592 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
594 _mesa_update_array_format(ctx
, vao
, attrib
, size
, type
, format
,
595 normalized
, integer
, doubles
, 0);
597 /* Reset the vertex attrib binding */
598 _mesa_vertex_attrib_binding(ctx
, vao
, attrib
, attrib
, true);
600 /* The Stride and Ptr fields are not set by update_array_format() */
601 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attrib
];
602 array
->Stride
= stride
;
605 /* Update the vertex buffer binding */
606 GLsizei effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
607 _mesa_bind_vertex_buffer(ctx
, vao
, attrib
,
608 ctx
->Array
.ArrayBufferObj
, (GLintptr
) ptr
,
609 effectiveStride
, true);
613 _mesa_VertexPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
616 GET_CURRENT_CONTEXT(ctx
);
617 FLUSH_VERTICES(ctx
, 0);
619 update_array(ctx
, VERT_ATTRIB_POS
, GL_RGBA
, 4, size
, type
, stride
,
620 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
625 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
627 GET_CURRENT_CONTEXT(ctx
);
629 FLUSH_VERTICES(ctx
, 0);
631 GLenum format
= GL_RGBA
;
632 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
633 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
634 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
635 DOUBLE_BIT
| HALF_BIT
|
636 UNSIGNED_INT_2_10_10_10_REV_BIT
|
637 INT_2_10_10_10_REV_BIT
);
639 if (!validate_array_and_format(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
640 legalTypes
, 2, 4, size
, type
, stride
,
641 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
,
642 ptr
, ctx
->Array
.VAO
))
645 update_array(ctx
, VERT_ATTRIB_POS
, format
, 4, size
, type
, stride
,
646 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
651 _mesa_NormalPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
653 GET_CURRENT_CONTEXT(ctx
);
654 FLUSH_VERTICES(ctx
, 0);
656 update_array(ctx
, VERT_ATTRIB_NORMAL
, GL_RGBA
, 3, 3, type
, stride
, GL_TRUE
,
657 GL_FALSE
, GL_FALSE
, ptr
);
662 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
664 GET_CURRENT_CONTEXT(ctx
);
666 FLUSH_VERTICES(ctx
, 0);
668 GLenum format
= GL_RGBA
;
669 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
670 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
671 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
672 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
673 UNSIGNED_INT_2_10_10_10_REV_BIT
|
674 INT_2_10_10_10_REV_BIT
);
676 if (!validate_array_and_format(ctx
, "glNormalPointer",
677 VERT_ATTRIB_NORMAL
, legalTypes
, 3, 3, 3,
678 type
, stride
, GL_TRUE
, GL_FALSE
,
679 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
682 update_array(ctx
, VERT_ATTRIB_NORMAL
, format
, 3, 3, type
, stride
, GL_TRUE
,
683 GL_FALSE
, GL_FALSE
, ptr
);
688 _mesa_ColorPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
691 GET_CURRENT_CONTEXT(ctx
);
692 FLUSH_VERTICES(ctx
, 0);
694 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
695 update_array(ctx
, VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
696 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
701 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
703 GET_CURRENT_CONTEXT(ctx
);
704 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
706 FLUSH_VERTICES(ctx
, 0);
708 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
709 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
710 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
711 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
712 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
713 INT_BIT
| UNSIGNED_INT_BIT
|
714 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
715 UNSIGNED_INT_2_10_10_10_REV_BIT
|
716 INT_2_10_10_10_REV_BIT
);
718 if (!validate_array_and_format(ctx
, "glColorPointer",
719 VERT_ATTRIB_COLOR0
, legalTypes
, sizeMin
,
720 BGRA_OR_4
, size
, type
, stride
, GL_TRUE
,
721 GL_FALSE
, GL_FALSE
, format
, ptr
,
725 update_array(ctx
, VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
726 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
731 _mesa_FogCoordPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
733 GET_CURRENT_CONTEXT(ctx
);
734 FLUSH_VERTICES(ctx
, 0);
736 update_array(ctx
, VERT_ATTRIB_FOG
, GL_RGBA
, 1, 1, type
, stride
, GL_FALSE
,
737 GL_FALSE
, GL_FALSE
, ptr
);
742 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
744 GET_CURRENT_CONTEXT(ctx
);
746 FLUSH_VERTICES(ctx
, 0);
748 GLenum format
= GL_RGBA
;
749 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
751 if (!validate_array_and_format(ctx
, "glFogCoordPointer",
752 VERT_ATTRIB_FOG
, legalTypes
, 1, 1, 1,
753 type
, stride
, GL_FALSE
, GL_FALSE
,
754 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
757 update_array(ctx
, VERT_ATTRIB_FOG
, format
, 1, 1, type
, stride
, GL_FALSE
,
758 GL_FALSE
, GL_FALSE
, ptr
);
763 _mesa_IndexPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
765 GET_CURRENT_CONTEXT(ctx
);
766 FLUSH_VERTICES(ctx
, 0);
768 update_array(ctx
, VERT_ATTRIB_COLOR_INDEX
, GL_RGBA
, 1, 1, type
, stride
,
769 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
774 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
776 GET_CURRENT_CONTEXT(ctx
);
778 FLUSH_VERTICES(ctx
, 0);
780 GLenum format
= GL_RGBA
;
781 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
782 FLOAT_BIT
| DOUBLE_BIT
);
784 if (!validate_array_and_format(ctx
, "glIndexPointer",
785 VERT_ATTRIB_COLOR_INDEX
,
786 legalTypes
, 1, 1, 1, type
, stride
,
787 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
,
788 ptr
, ctx
->Array
.VAO
))
791 update_array(ctx
, VERT_ATTRIB_COLOR_INDEX
, format
, 1, 1, type
, stride
,
792 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
797 _mesa_SecondaryColorPointer_no_error(GLint size
, GLenum type
,
798 GLsizei stride
, const GLvoid
*ptr
)
800 GET_CURRENT_CONTEXT(ctx
);
801 FLUSH_VERTICES(ctx
, 0);
803 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
804 update_array(ctx
, VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
805 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
810 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
811 GLsizei stride
, const GLvoid
*ptr
)
813 GET_CURRENT_CONTEXT(ctx
);
815 FLUSH_VERTICES(ctx
, 0);
817 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
818 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
819 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
820 INT_BIT
| UNSIGNED_INT_BIT
|
821 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
822 UNSIGNED_INT_2_10_10_10_REV_BIT
|
823 INT_2_10_10_10_REV_BIT
);
825 if (!validate_array_and_format(ctx
, "glSecondaryColorPointer",
826 VERT_ATTRIB_COLOR1
, legalTypes
, 3,
827 BGRA_OR_4
, size
, type
, stride
,
828 GL_TRUE
, GL_FALSE
, GL_FALSE
, format
, ptr
,
832 update_array(ctx
, VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
833 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
838 _mesa_TexCoordPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
841 GET_CURRENT_CONTEXT(ctx
);
842 const GLuint unit
= ctx
->Array
.ActiveTexture
;
843 FLUSH_VERTICES(ctx
, 0);
845 update_array(ctx
, VERT_ATTRIB_TEX(unit
), GL_RGBA
, 4, size
, type
,
846 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
851 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
854 GET_CURRENT_CONTEXT(ctx
);
855 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
856 const GLuint unit
= ctx
->Array
.ActiveTexture
;
858 FLUSH_VERTICES(ctx
, 0);
860 GLenum format
= GL_RGBA
;
861 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
862 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
863 : (SHORT_BIT
| INT_BIT
|
864 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
865 UNSIGNED_INT_2_10_10_10_REV_BIT
|
866 INT_2_10_10_10_REV_BIT
);
868 if (!validate_array_and_format(ctx
, "glTexCoordPointer",
869 VERT_ATTRIB_TEX(unit
), legalTypes
,
870 sizeMin
, 4, size
, type
, stride
,
871 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
,
875 update_array(ctx
, VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
876 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
881 _mesa_EdgeFlagPointer_no_error(GLsizei stride
, const GLvoid
*ptr
)
883 /* this is the same type that glEdgeFlag uses */
884 const GLboolean integer
= GL_FALSE
;
885 GET_CURRENT_CONTEXT(ctx
);
886 FLUSH_VERTICES(ctx
, 0);
888 update_array(ctx
, VERT_ATTRIB_EDGEFLAG
, GL_RGBA
, 1, 1, GL_UNSIGNED_BYTE
,
889 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
894 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
896 /* this is the same type that glEdgeFlag uses */
897 const GLboolean integer
= GL_FALSE
;
898 GET_CURRENT_CONTEXT(ctx
);
900 FLUSH_VERTICES(ctx
, 0);
902 GLenum format
= GL_RGBA
;
903 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
905 if (!validate_array_and_format(ctx
, "glEdgeFlagPointer",
906 VERT_ATTRIB_EDGEFLAG
, legalTypes
,
907 1, 1, 1, GL_UNSIGNED_BYTE
, stride
,
908 GL_FALSE
, integer
, GL_FALSE
, format
, ptr
,
912 update_array(ctx
, VERT_ATTRIB_EDGEFLAG
, format
, 1, 1, GL_UNSIGNED_BYTE
,
913 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
918 _mesa_PointSizePointerOES_no_error(GLenum type
, GLsizei stride
,
921 GET_CURRENT_CONTEXT(ctx
);
922 FLUSH_VERTICES(ctx
, 0);
924 update_array(ctx
, VERT_ATTRIB_POINT_SIZE
, GL_RGBA
, 1, 1, type
, stride
,
925 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
930 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
932 GET_CURRENT_CONTEXT(ctx
);
934 FLUSH_VERTICES(ctx
, 0);
936 GLenum format
= GL_RGBA
;
937 if (ctx
->API
!= API_OPENGLES
) {
938 _mesa_error(ctx
, GL_INVALID_OPERATION
,
939 "glPointSizePointer(ES 1.x only)");
943 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
945 if (!validate_array_and_format(ctx
, "glPointSizePointer",
946 VERT_ATTRIB_POINT_SIZE
, legalTypes
,
947 1, 1, 1, type
, stride
, GL_FALSE
, GL_FALSE
,
948 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
951 update_array(ctx
, VERT_ATTRIB_POINT_SIZE
, format
, 1, 1, type
, stride
,
952 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
957 _mesa_VertexAttribPointer_no_error(GLuint index
, GLint size
, GLenum type
,
958 GLboolean normalized
,
959 GLsizei stride
, const GLvoid
*ptr
)
961 GET_CURRENT_CONTEXT(ctx
);
963 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
964 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
965 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
970 * Set a generic vertex attribute array.
971 * Note that these arrays DO NOT alias the conventional GL vertex arrays
972 * (position, normal, color, fog, texcoord, etc).
975 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
976 GLboolean normalized
,
977 GLsizei stride
, const GLvoid
*ptr
)
979 GET_CURRENT_CONTEXT(ctx
);
981 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
982 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
983 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(idx)");
987 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
988 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
989 INT_BIT
| UNSIGNED_INT_BIT
|
990 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
991 FIXED_ES_BIT
| FIXED_GL_BIT
|
992 UNSIGNED_INT_2_10_10_10_REV_BIT
|
993 INT_2_10_10_10_REV_BIT
|
994 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
996 if (!validate_array_and_format(ctx
, "glVertexAttribPointer",
997 VERT_ATTRIB_GENERIC(index
), legalTypes
,
998 1, BGRA_OR_4
, size
, type
, stride
,
999 normalized
, GL_FALSE
, GL_FALSE
, format
,
1000 ptr
, ctx
->Array
.VAO
))
1003 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1004 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
1009 _mesa_VertexAttribIPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1010 GLsizei stride
, const GLvoid
*ptr
)
1012 const GLboolean normalized
= GL_FALSE
;
1013 const GLboolean integer
= GL_TRUE
;
1014 GET_CURRENT_CONTEXT(ctx
);
1016 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1017 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1022 * GL_EXT_gpu_shader4 / GL 3.0.
1023 * Set an integer-valued vertex attribute array.
1024 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1025 * (position, normal, color, fog, texcoord, etc).
1028 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
1029 GLsizei stride
, const GLvoid
*ptr
)
1031 const GLboolean normalized
= GL_FALSE
;
1032 const GLboolean integer
= GL_TRUE
;
1033 GET_CURRENT_CONTEXT(ctx
);
1035 GLenum format
= GL_RGBA
;
1036 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1037 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
1041 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1042 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1043 INT_BIT
| UNSIGNED_INT_BIT
);
1045 if (!validate_array_and_format(ctx
, "glVertexAttribIPointer",
1046 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1047 1, 4, size
, type
, stride
,
1048 normalized
, integer
, GL_FALSE
, format
,
1049 ptr
, ctx
->Array
.VAO
))
1052 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1053 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1058 _mesa_VertexAttribLPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1059 GLsizei stride
, const GLvoid
*ptr
)
1061 GET_CURRENT_CONTEXT(ctx
);
1063 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1064 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1069 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
1070 GLsizei stride
, const GLvoid
*ptr
)
1072 GET_CURRENT_CONTEXT(ctx
);
1074 GLenum format
= GL_RGBA
;
1075 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1076 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
1080 const GLbitfield legalTypes
= DOUBLE_BIT
;
1082 if (!validate_array_and_format(ctx
, "glVertexAttribLPointer",
1083 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1084 1, 4, size
, type
, stride
,
1085 GL_FALSE
, GL_FALSE
, GL_TRUE
, format
,
1086 ptr
, ctx
->Array
.VAO
))
1089 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1090 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1095 _mesa_enable_vertex_array_attrib(struct gl_context
*ctx
,
1096 struct gl_vertex_array_object
*vao
,
1097 gl_vert_attrib attrib
, bool flush_vertices
)
1099 assert(attrib
< ARRAY_SIZE(vao
->VertexAttrib
));
1101 if (!vao
->VertexAttrib
[attrib
].Enabled
) {
1102 /* was disabled, now being enabled */
1103 if (flush_vertices
) {
1104 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
1107 vao
->VertexAttrib
[attrib
].Enabled
= GL_TRUE
;
1108 const GLbitfield array_bit
= VERT_BIT(attrib
);
1109 vao
->_Enabled
|= array_bit
;
1110 vao
->NewArrays
|= array_bit
;
1112 /* Update the map mode if needed */
1113 if (array_bit
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1114 update_attribute_map_mode(ctx
, vao
);
1119 enable_vertex_array_attrib(struct gl_context
*ctx
,
1120 struct gl_vertex_array_object
*vao
,
1124 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1125 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
1129 _mesa_enable_vertex_array_attrib(ctx
, vao
,
1130 VERT_ATTRIB_GENERIC(index
), true);
1135 _mesa_EnableVertexAttribArray(GLuint index
)
1137 GET_CURRENT_CONTEXT(ctx
);
1138 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
1139 "glEnableVertexAttribArray");
1144 _mesa_EnableVertexAttribArray_no_error(GLuint index
)
1146 GET_CURRENT_CONTEXT(ctx
);
1147 _mesa_enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1148 VERT_ATTRIB_GENERIC(index
), true);
1153 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1155 GET_CURRENT_CONTEXT(ctx
);
1156 struct gl_vertex_array_object
*vao
;
1158 /* The ARB_direct_state_access specification says:
1160 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1161 * and DisableVertexArrayAttrib if <vaobj> is not
1162 * [compatibility profile: zero or] the name of an existing vertex
1165 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
1169 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
1174 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1176 GET_CURRENT_CONTEXT(ctx
);
1177 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1178 _mesa_enable_vertex_array_attrib(ctx
, vao
,
1179 VERT_ATTRIB_GENERIC(index
), true);
1184 _mesa_disable_vertex_array_attrib(struct gl_context
*ctx
,
1185 struct gl_vertex_array_object
*vao
,
1186 gl_vert_attrib attrib
, bool flush_vertices
)
1188 assert(attrib
< ARRAY_SIZE(vao
->VertexAttrib
));
1190 if (vao
->VertexAttrib
[attrib
].Enabled
) {
1191 /* was enabled, now being disabled */
1192 if (flush_vertices
) {
1193 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
1196 vao
->VertexAttrib
[attrib
].Enabled
= GL_FALSE
;
1197 const GLbitfield array_bit
= VERT_BIT(attrib
);
1198 vao
->_Enabled
&= ~array_bit
;
1199 vao
->NewArrays
|= array_bit
;
1201 /* Update the map mode if needed */
1202 if (array_bit
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1203 update_attribute_map_mode(ctx
, vao
);
1209 _mesa_DisableVertexAttribArray(GLuint index
)
1211 GET_CURRENT_CONTEXT(ctx
);
1213 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1214 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexAttribArray(index)");
1218 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1219 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
, true);
1224 _mesa_DisableVertexAttribArray_no_error(GLuint index
)
1226 GET_CURRENT_CONTEXT(ctx
);
1227 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1228 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
, true);
1233 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1235 GET_CURRENT_CONTEXT(ctx
);
1236 struct gl_vertex_array_object
*vao
;
1238 /* The ARB_direct_state_access specification says:
1240 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1241 * and DisableVertexArrayAttrib if <vaobj> is not
1242 * [compatibility profile: zero or] the name of an existing vertex
1245 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
1249 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1250 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
1254 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1255 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
, true);
1260 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1262 GET_CURRENT_CONTEXT(ctx
);
1263 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1264 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1265 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
, true);
1270 * Return info for a vertex attribute array (no alias with legacy
1271 * vertex attributes (pos, normal, color, etc)). This function does
1272 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
1275 get_vertex_array_attrib(struct gl_context
*ctx
,
1276 const struct gl_vertex_array_object
*vao
,
1277 GLuint index
, GLenum pname
,
1280 const struct gl_array_attributes
*array
;
1282 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1283 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
1287 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
1289 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
1292 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
1293 return array
->Enabled
;
1294 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
1295 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
1296 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
1297 return array
->Stride
;
1298 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
1300 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
1301 return array
->Normalized
;
1302 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
1303 return vao
->BufferBinding
[array
->BufferBindingIndex
].BufferObj
->Name
;
1304 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
1305 if ((_mesa_is_desktop_gl(ctx
)
1306 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
1307 || _mesa_is_gles3(ctx
)) {
1308 return array
->Integer
;
1311 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
1312 if (_mesa_is_desktop_gl(ctx
)) {
1313 return array
->Doubles
;
1316 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
1317 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
1318 || _mesa_is_gles3(ctx
)) {
1319 return vao
->BufferBinding
[array
->BufferBindingIndex
].InstanceDivisor
;
1322 case GL_VERTEX_ATTRIB_BINDING
:
1323 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
1324 return array
->BufferBindingIndex
- VERT_ATTRIB_GENERIC0
;
1327 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
1328 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
1329 return array
->RelativeOffset
;
1333 ; /* fall-through */
1337 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
1342 static const GLfloat
*
1343 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
1346 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
1347 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
1351 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1352 _mesa_error(ctx
, GL_INVALID_VALUE
,
1353 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
1357 assert(VERT_ATTRIB_GENERIC(index
) <
1358 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1360 FLUSH_CURRENT(ctx
, 0);
1361 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
1365 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
1367 GET_CURRENT_CONTEXT(ctx
);
1369 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1370 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
1376 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1378 "glGetVertexAttribfv");
1384 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1386 GET_CURRENT_CONTEXT(ctx
);
1388 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1389 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
1391 params
[0] = (GLdouble
) v
[0];
1392 params
[1] = (GLdouble
) v
[1];
1393 params
[2] = (GLdouble
) v
[2];
1394 params
[3] = (GLdouble
) v
[3];
1398 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1400 "glGetVertexAttribdv");
1405 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1407 GET_CURRENT_CONTEXT(ctx
);
1409 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1411 (const GLdouble
*)get_current_attrib(ctx
, index
,
1412 "glGetVertexAttribLdv");
1421 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1423 "glGetVertexAttribLdv");
1428 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
1430 GET_CURRENT_CONTEXT(ctx
);
1432 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1433 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1435 /* XXX should floats in[0,1] be scaled to full int range? */
1436 params
[0] = (GLint
) v
[0];
1437 params
[1] = (GLint
) v
[1];
1438 params
[2] = (GLint
) v
[2];
1439 params
[3] = (GLint
) v
[3];
1443 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1445 "glGetVertexAttribiv");
1450 _mesa_GetVertexAttribLui64vARB(GLuint index
, GLenum pname
, GLuint64EXT
*params
)
1452 GET_CURRENT_CONTEXT(ctx
);
1454 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1456 (const GLuint64
*)get_current_attrib(ctx
, index
,
1457 "glGetVertexAttribLui64vARB");
1466 params
[0] = (GLuint64
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1468 "glGetVertexAttribLui64vARB");
1475 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1477 GET_CURRENT_CONTEXT(ctx
);
1479 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1480 const GLint
*v
= (const GLint
*)
1481 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1487 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1489 "glGetVertexAttribIiv");
1496 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1498 GET_CURRENT_CONTEXT(ctx
);
1500 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1501 const GLuint
*v
= (const GLuint
*)
1502 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1508 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1510 "glGetVertexAttribIuiv");
1516 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1518 GET_CURRENT_CONTEXT(ctx
);
1520 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1521 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1525 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1526 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1530 assert(VERT_ATTRIB_GENERIC(index
) <
1531 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1533 *pointer
= (GLvoid
*)
1534 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1538 /** ARB_direct_state_access */
1540 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
1541 GLenum pname
, GLint
*params
)
1543 GET_CURRENT_CONTEXT(ctx
);
1544 struct gl_vertex_array_object
*vao
;
1546 /* The ARB_direct_state_access specification says:
1548 * "An INVALID_OPERATION error is generated if <vaobj> is not
1549 * [compatibility profile: zero or] the name of an existing
1550 * vertex array object."
1552 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexediv");
1556 /* The ARB_direct_state_access specification says:
1558 * "For GetVertexArrayIndexediv, <pname> must be one of
1559 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1560 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1561 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1562 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1563 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1567 * "Add GetVertexArrayIndexediv in 'Get Command' for
1568 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1569 * VERTEX_ATTRIB_BINDING,
1570 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1571 * VERTEX_BINDING_OFFSET, and
1572 * VERTEX_BINDING_STRIDE states"
1574 * The only parameter name common to both lists is
1575 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1576 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1577 * pretty clear however that the intent is that it should be possible
1578 * to query all vertex attrib and binding states that can be set with
1582 case GL_VERTEX_BINDING_OFFSET
:
1583 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1585 case GL_VERTEX_BINDING_STRIDE
:
1586 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
1588 case GL_VERTEX_BINDING_DIVISOR
:
1589 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
1591 case GL_VERTEX_BINDING_BUFFER
:
1592 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
1595 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
1596 "glGetVertexArrayIndexediv");
1603 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
1604 GLenum pname
, GLint64
*params
)
1606 GET_CURRENT_CONTEXT(ctx
);
1607 struct gl_vertex_array_object
*vao
;
1609 /* The ARB_direct_state_access specification says:
1611 * "An INVALID_OPERATION error is generated if <vaobj> is not
1612 * [compatibility profile: zero or] the name of an existing
1613 * vertex array object."
1615 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexed64iv");
1619 /* The ARB_direct_state_access specification says:
1621 * "For GetVertexArrayIndexed64iv, <pname> must be
1622 * VERTEX_BINDING_OFFSET."
1626 * "An INVALID_ENUM error is generated if <pname> is not one of
1627 * the valid values listed above for the corresponding command."
1629 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
1630 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
1631 "pname != GL_VERTEX_BINDING_OFFSET)");
1635 /* The ARB_direct_state_access specification says:
1637 * "An INVALID_VALUE error is generated if <index> is greater than
1638 * or equal to the value of MAX_VERTEX_ATTRIBS."
1640 * Since the index refers to a buffer binding in this case, the intended
1641 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1642 * required to be the same, so in practice this doesn't matter.
1644 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
1645 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
1646 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1647 index
, ctx
->Const
.MaxVertexAttribBindings
);
1651 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1656 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1657 GLsizei count
, const GLvoid
*ptr
)
1660 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1665 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1669 _mesa_NormalPointer(type
, stride
, ptr
);
1674 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1678 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1683 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1687 _mesa_IndexPointer(type
, stride
, ptr
);
1692 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1693 GLsizei count
, const GLvoid
*ptr
)
1696 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1701 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1704 _mesa_EdgeFlagPointer(stride
, ptr
);
1709 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1711 GET_CURRENT_CONTEXT(ctx
);
1712 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1713 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1714 GLenum ctype
= 0; /* color type */
1715 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1716 const GLint toffset
= 0; /* always zero */
1717 GLint defstride
; /* default stride */
1720 FLUSH_VERTICES(ctx
, 0);
1722 f
= sizeof(GLfloat
);
1723 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1726 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1732 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1733 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1738 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1739 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1744 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1745 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1746 ctype
= GL_UNSIGNED_BYTE
;
1749 defstride
= c
+ 2*f
;
1752 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1753 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1754 ctype
= GL_UNSIGNED_BYTE
;
1757 defstride
= c
+ 3*f
;
1760 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1761 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1768 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1769 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1774 case GL_C4F_N3F_V3F
:
1775 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1776 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1784 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1785 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1790 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1791 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1795 case GL_T2F_C4UB_V3F
:
1796 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1797 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1798 ctype
= GL_UNSIGNED_BYTE
;
1803 case GL_T2F_C3F_V3F
:
1804 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1805 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1811 case GL_T2F_N3F_V3F
:
1812 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1813 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1818 case GL_T2F_C4F_N3F_V3F
:
1819 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1820 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1827 case GL_T4F_C4F_N3F_V4F
:
1828 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1829 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1837 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1845 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1846 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1847 /* XXX also disable secondary color and generic arrays? */
1851 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1852 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1853 (GLubyte
*) pointer
+ toffset
);
1856 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1861 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1862 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1863 (GLubyte
*) pointer
+ coffset
);
1866 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1872 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1873 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1876 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1880 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1881 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1882 (GLubyte
*) pointer
+ voffset
);
1887 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1889 GET_CURRENT_CONTEXT(ctx
);
1891 FLUSH_VERTICES(ctx
, 0);
1893 if (MESA_VERBOSE
& VERBOSE_API
)
1894 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1897 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1901 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1904 if (ctx
->Array
.LockCount
!= 0) {
1905 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1909 ctx
->Array
.LockFirst
= first
;
1910 ctx
->Array
.LockCount
= count
;
1912 ctx
->NewState
|= _NEW_ARRAY
;
1917 _mesa_UnlockArraysEXT( void )
1919 GET_CURRENT_CONTEXT(ctx
);
1921 FLUSH_VERTICES(ctx
, 0);
1923 if (MESA_VERBOSE
& VERBOSE_API
)
1924 _mesa_debug(ctx
, "glUnlockArrays\n");
1926 if (ctx
->Array
.LockCount
== 0) {
1927 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1931 ctx
->Array
.LockFirst
= 0;
1932 ctx
->Array
.LockCount
= 0;
1933 ctx
->NewState
|= _NEW_ARRAY
;
1937 /* GL_IBM_multimode_draw_arrays */
1939 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1940 const GLsizei
* count
,
1941 GLsizei primcount
, GLint modestride
)
1943 GET_CURRENT_CONTEXT(ctx
);
1946 FLUSH_VERTICES(ctx
, 0);
1948 for ( i
= 0 ; i
< primcount
; i
++ ) {
1949 if ( count
[i
] > 0 ) {
1950 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1951 CALL_DrawArrays(ctx
->CurrentServerDispatch
, ( m
, first
[i
], count
[i
] ));
1957 /* GL_IBM_multimode_draw_arrays */
1959 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1960 GLenum type
, const GLvoid
* const * indices
,
1961 GLsizei primcount
, GLint modestride
)
1963 GET_CURRENT_CONTEXT(ctx
);
1966 FLUSH_VERTICES(ctx
, 0);
1968 /* XXX not sure about ARB_vertex_buffer_object handling here */
1970 for ( i
= 0 ; i
< primcount
; i
++ ) {
1971 if ( count
[i
] > 0 ) {
1972 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1973 CALL_DrawElements(ctx
->CurrentServerDispatch
, ( m
, count
[i
], type
,
1981 primitive_restart_index(struct gl_context
*ctx
, GLuint index
)
1983 if (ctx
->Array
.RestartIndex
!= index
) {
1984 FLUSH_VERTICES(ctx
, 0);
1985 ctx
->Array
.RestartIndex
= index
;
1991 * GL_NV_primitive_restart and GL 3.1
1994 _mesa_PrimitiveRestartIndex_no_error(GLuint index
)
1996 GET_CURRENT_CONTEXT(ctx
);
1997 primitive_restart_index(ctx
, index
);
2002 _mesa_PrimitiveRestartIndex(GLuint index
)
2004 GET_CURRENT_CONTEXT(ctx
);
2006 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
2007 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
2011 primitive_restart_index(ctx
, index
);
2016 _mesa_VertexAttribDivisor_no_error(GLuint index
, GLuint divisor
)
2018 GET_CURRENT_CONTEXT(ctx
);
2020 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2021 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2023 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2025 /* The ARB_vertex_attrib_binding spec says:
2029 * void VertexAttribDivisor(uint index, uint divisor);
2031 * is equivalent to (assuming no errors are generated):
2033 * VertexAttribBinding(index, index);
2034 * VertexBindingDivisor(index, divisor);"
2036 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
, true);
2037 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2042 * See GL_ARB_instanced_arrays.
2043 * Note that the instance divisor only applies to generic arrays, not
2044 * the legacy vertex arrays.
2047 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
2049 GET_CURRENT_CONTEXT(ctx
);
2051 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2052 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2054 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2055 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
2059 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2060 _mesa_error(ctx
, GL_INVALID_VALUE
,
2061 "glVertexAttribDivisor(index = %u)", index
);
2065 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2067 /* The ARB_vertex_attrib_binding spec says:
2071 * void VertexAttribDivisor(uint index, uint divisor);
2073 * is equivalent to (assuming no errors are generated):
2075 * VertexAttribBinding(index, index);
2076 * VertexBindingDivisor(index, divisor);"
2078 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
, true);
2079 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2083 static ALWAYS_INLINE
void
2084 vertex_array_vertex_buffer(struct gl_context
*ctx
,
2085 struct gl_vertex_array_object
*vao
,
2086 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2087 GLsizei stride
, bool no_error
, const char *func
)
2089 struct gl_buffer_object
*vbo
;
2091 vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
2092 vbo
= vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
2093 } else if (buffer
!= 0) {
2094 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
2096 if (!no_error
&& !vbo
&& _mesa_is_gles31(ctx
)) {
2097 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", func
);
2100 /* From the GL_ARB_vertex_attrib_array spec:
2102 * "[Core profile only:]
2103 * An INVALID_OPERATION error is generated if buffer is not zero or a
2104 * name returned from a previous call to GenBuffers, or if such a name
2105 * has since been deleted with DeleteBuffers.
2107 * Otherwise, we fall back to the same compat profile behavior as other
2108 * object references (automatically gen it).
2110 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
2113 /* The ARB_vertex_attrib_binding spec says:
2115 * "If <buffer> is zero, any buffer object attached to this
2116 * bindpoint is detached."
2118 vbo
= ctx
->Shared
->NullBufferObj
;
2121 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
2122 vbo
, offset
, stride
, true);
2127 * GL_ARB_vertex_attrib_binding
2130 vertex_array_vertex_buffer_err(struct gl_context
*ctx
,
2131 struct gl_vertex_array_object
*vao
,
2132 GLuint bindingIndex
, GLuint buffer
,
2133 GLintptr offset
, GLsizei stride
,
2136 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2138 /* The ARB_vertex_attrib_binding spec says:
2140 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2141 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2143 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2144 _mesa_error(ctx
, GL_INVALID_VALUE
,
2145 "%s(bindingindex=%u > "
2146 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2147 func
, bindingIndex
);
2151 /* The ARB_vertex_attrib_binding spec says:
2153 * "The error INVALID_VALUE is generated if <stride> or <offset>
2157 _mesa_error(ctx
, GL_INVALID_VALUE
,
2158 "%s(offset=%" PRId64
" < 0)",
2159 func
, (int64_t) offset
);
2164 _mesa_error(ctx
, GL_INVALID_VALUE
,
2165 "%s(stride=%d < 0)", func
, stride
);
2169 if (((_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
2170 stride
> ctx
->Const
.MaxVertexAttribStride
) {
2171 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
2172 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
2176 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2177 stride
, false, func
);
2182 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex
, GLuint buffer
,
2183 GLintptr offset
, GLsizei stride
)
2185 GET_CURRENT_CONTEXT(ctx
);
2186 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
2187 buffer
, offset
, stride
, true,
2188 "glBindVertexBuffer");
2193 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2196 GET_CURRENT_CONTEXT(ctx
);
2198 /* The ARB_vertex_attrib_binding spec says:
2200 * "An INVALID_OPERATION error is generated if no vertex array object
2203 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2204 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2205 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2206 "glBindVertexBuffer(No array object bound)");
2210 vertex_array_vertex_buffer_err(ctx
, ctx
->Array
.VAO
, bindingIndex
,
2211 buffer
, offset
, stride
,
2212 "glBindVertexBuffer");
2217 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj
, GLuint bindingIndex
,
2218 GLuint buffer
, GLintptr offset
,
2221 GET_CURRENT_CONTEXT(ctx
);
2223 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2224 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2225 stride
, true, "glVertexArrayVertexBuffer");
2230 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
2231 GLintptr offset
, GLsizei stride
)
2233 GET_CURRENT_CONTEXT(ctx
);
2234 struct gl_vertex_array_object
*vao
;
2236 /* The ARB_direct_state_access specification says:
2238 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2239 * if <vaobj> is not [compatibility profile: zero or] the name of an
2240 * existing vertex array object."
2242 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
2246 vertex_array_vertex_buffer_err(ctx
, vao
, bindingIndex
, buffer
, offset
,
2247 stride
, "glVertexArrayVertexBuffer");
2251 static ALWAYS_INLINE
void
2252 vertex_array_vertex_buffers(struct gl_context
*ctx
,
2253 struct gl_vertex_array_object
*vao
,
2254 GLuint first
, GLsizei count
, const GLuint
*buffers
,
2255 const GLintptr
*offsets
, const GLsizei
*strides
,
2256 bool no_error
, const char *func
)
2262 * The ARB_multi_bind spec says:
2264 * "If <buffers> is NULL, each affected vertex buffer binding point
2265 * from <first> through <first>+<count>-1 will be reset to have no
2266 * bound buffer object. In this case, the offsets and strides
2267 * associated with the binding points are set to default values,
2268 * ignoring <offsets> and <strides>."
2270 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
2272 for (i
= 0; i
< count
; i
++)
2273 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
2279 /* Note that the error semantics for multi-bind commands differ from
2280 * those of other GL commands.
2282 * The Issues section in the ARB_multi_bind spec says:
2284 * "(11) Typically, OpenGL specifies that if an error is generated by
2285 * a command, that command has no effect. This is somewhat
2286 * unfortunate for multi-bind commands, because it would require
2287 * a first pass to scan the entire list of bound objects for
2288 * errors and then a second pass to actually perform the
2289 * bindings. Should we have different error semantics?
2291 * RESOLVED: Yes. In this specification, when the parameters for
2292 * one of the <count> binding points are invalid, that binding
2293 * point is not updated and an error will be generated. However,
2294 * other binding points in the same command will be updated if
2295 * their parameters are valid and no other error occurs."
2298 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
2300 for (i
= 0; i
< count
; i
++) {
2301 struct gl_buffer_object
*vbo
;
2304 /* The ARB_multi_bind spec says:
2306 * "An INVALID_VALUE error is generated if any value in
2307 * <offsets> or <strides> is negative (per binding)."
2309 if (offsets
[i
] < 0) {
2310 _mesa_error(ctx
, GL_INVALID_VALUE
,
2311 "%s(offsets[%u]=%" PRId64
" < 0)",
2312 func
, i
, (int64_t) offsets
[i
]);
2316 if (strides
[i
] < 0) {
2317 _mesa_error(ctx
, GL_INVALID_VALUE
,
2318 "%s(strides[%u]=%d < 0)",
2319 func
, i
, strides
[i
]);
2323 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44 &&
2324 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
2325 _mesa_error(ctx
, GL_INVALID_VALUE
,
2326 "%s(strides[%u]=%d > "
2327 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
2333 struct gl_vertex_buffer_binding
*binding
=
2334 &vao
->BufferBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
2336 if (buffers
[i
] == binding
->BufferObj
->Name
)
2337 vbo
= binding
->BufferObj
;
2339 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
2344 vbo
= ctx
->Shared
->NullBufferObj
;
2347 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
2348 vbo
, offsets
[i
], strides
[i
], true);
2351 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
2356 vertex_array_vertex_buffers_err(struct gl_context
*ctx
,
2357 struct gl_vertex_array_object
*vao
,
2358 GLuint first
, GLsizei count
,
2359 const GLuint
*buffers
, const GLintptr
*offsets
,
2360 const GLsizei
*strides
, const char *func
)
2362 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2364 /* The ARB_multi_bind spec says:
2366 * "An INVALID_OPERATION error is generated if <first> + <count>
2367 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
2369 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
2370 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2371 "%s(first=%u + count=%d > the value of "
2372 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
2373 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
2377 vertex_array_vertex_buffers(ctx
, vao
, first
, count
, buffers
, offsets
,
2378 strides
, false, func
);
2383 _mesa_BindVertexBuffers_no_error(GLuint first
, GLsizei count
,
2384 const GLuint
*buffers
, const GLintptr
*offsets
,
2385 const GLsizei
*strides
)
2387 GET_CURRENT_CONTEXT(ctx
);
2389 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
2390 buffers
, offsets
, strides
, true,
2391 "glBindVertexBuffers");
2396 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
2397 const GLintptr
*offsets
, const GLsizei
*strides
)
2399 GET_CURRENT_CONTEXT(ctx
);
2401 /* The ARB_vertex_attrib_binding spec says:
2403 * "An INVALID_OPERATION error is generated if no
2404 * vertex array object is bound."
2406 if (ctx
->API
== API_OPENGL_CORE
&&
2407 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2408 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2409 "glBindVertexBuffers(No array object bound)");
2413 vertex_array_vertex_buffers_err(ctx
, ctx
->Array
.VAO
, first
, count
,
2414 buffers
, offsets
, strides
,
2415 "glBindVertexBuffers");
2420 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj
, GLuint first
,
2421 GLsizei count
, const GLuint
*buffers
,
2422 const GLintptr
*offsets
,
2423 const GLsizei
*strides
)
2425 GET_CURRENT_CONTEXT(ctx
);
2427 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2428 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
2429 buffers
, offsets
, strides
, true,
2430 "glVertexArrayVertexBuffers");
2435 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
2436 const GLuint
*buffers
,
2437 const GLintptr
*offsets
, const GLsizei
*strides
)
2439 GET_CURRENT_CONTEXT(ctx
);
2440 struct gl_vertex_array_object
*vao
;
2442 /* The ARB_direct_state_access specification says:
2444 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2445 * if <vaobj> is not [compatibility profile: zero or] the name of an
2446 * existing vertex array object."
2448 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
2452 vertex_array_vertex_buffers_err(ctx
, vao
, first
, count
,
2453 buffers
, offsets
, strides
,
2454 "glVertexArrayVertexBuffers");
2459 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
2460 GLboolean normalized
, GLboolean integer
,
2461 GLboolean doubles
, GLbitfield legalTypes
,
2462 GLsizei sizeMax
, GLuint relativeOffset
,
2465 GET_CURRENT_CONTEXT(ctx
);
2466 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2468 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
2470 if (!_mesa_is_no_error_enabled(ctx
)) {
2471 /* The ARB_vertex_attrib_binding spec says:
2473 * "An INVALID_OPERATION error is generated under any of the
2474 * following conditions:
2475 * - if no vertex array object is currently bound (see section
2479 * This error condition only applies to VertexAttribFormat and
2480 * VertexAttribIFormat in the extension spec, but we assume that this
2481 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2482 * to all three functions.
2484 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2485 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2486 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2487 "%s(No array object bound)", func
);
2491 /* The ARB_vertex_attrib_binding spec says:
2493 * "The error INVALID_VALUE is generated if index is greater than or
2494 * equal to the value of MAX_VERTEX_ATTRIBS."
2496 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2497 _mesa_error(ctx
, GL_INVALID_VALUE
,
2498 "%s(attribindex=%u > "
2499 "GL_MAX_VERTEX_ATTRIBS)",
2504 if (!validate_array_format(ctx
, func
, ctx
->Array
.VAO
,
2505 VERT_ATTRIB_GENERIC(attribIndex
),
2506 legalTypes
, 1, sizeMax
, size
, type
,
2507 normalized
, integer
, doubles
, relativeOffset
,
2513 FLUSH_VERTICES(ctx
, 0);
2515 _mesa_update_array_format(ctx
, ctx
->Array
.VAO
,
2516 VERT_ATTRIB_GENERIC(attribIndex
), size
, type
,
2517 format
, normalized
, integer
, doubles
,
2523 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2524 GLboolean normalized
, GLuint relativeOffset
)
2526 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
2527 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2528 BGRA_OR_4
, relativeOffset
,
2529 "glVertexAttribFormat");
2534 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2535 GLuint relativeOffset
)
2537 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
2538 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
2539 relativeOffset
, "glVertexAttribIFormat");
2544 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2545 GLuint relativeOffset
)
2547 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
2548 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
2549 relativeOffset
, "glVertexAttribLFormat");
2554 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2555 GLenum type
, GLboolean normalized
,
2556 GLboolean integer
, GLboolean doubles
,
2557 GLbitfield legalTypes
, GLsizei sizeMax
,
2558 GLuint relativeOffset
, const char *func
)
2560 GET_CURRENT_CONTEXT(ctx
);
2561 struct gl_vertex_array_object
*vao
;
2563 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2565 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
2567 if (_mesa_is_no_error_enabled(ctx
)) {
2568 vao
= _mesa_lookup_vao(ctx
, vaobj
);
2572 /* The ARB_direct_state_access spec says:
2574 * "An INVALID_OPERATION error is generated by
2575 * VertexArrayAttrib*Format if <vaobj> is not [compatibility profile:
2576 * zero or] the name of an existing vertex array object."
2578 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
2582 /* The ARB_vertex_attrib_binding spec says:
2584 * "The error INVALID_VALUE is generated if index is greater than or
2585 * equal to the value of MAX_VERTEX_ATTRIBS."
2587 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2588 _mesa_error(ctx
, GL_INVALID_VALUE
,
2589 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2594 if (!validate_array_format(ctx
, func
, vao
,
2595 VERT_ATTRIB_GENERIC(attribIndex
),
2596 legalTypes
, 1, sizeMax
, size
, type
,
2597 normalized
, integer
, doubles
, relativeOffset
,
2603 FLUSH_VERTICES(ctx
, 0);
2605 _mesa_update_array_format(ctx
, vao
, VERT_ATTRIB_GENERIC(attribIndex
), size
,
2606 type
, format
, normalized
, integer
, doubles
,
2612 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2613 GLenum type
, GLboolean normalized
,
2614 GLuint relativeOffset
)
2616 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
2617 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2618 BGRA_OR_4
, relativeOffset
,
2619 "glVertexArrayAttribFormat");
2624 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
2625 GLint size
, GLenum type
,
2626 GLuint relativeOffset
)
2628 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2629 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
2631 "glVertexArrayAttribIFormat");
2636 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
2637 GLint size
, GLenum type
,
2638 GLuint relativeOffset
)
2640 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2641 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
2643 "glVertexArrayAttribLFormat");
2648 vertex_array_attrib_binding(struct gl_context
*ctx
,
2649 struct gl_vertex_array_object
*vao
,
2650 GLuint attribIndex
, GLuint bindingIndex
,
2653 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2655 /* The ARB_vertex_attrib_binding spec says:
2657 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2658 * <bindingindex> must be less than the value of
2659 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2662 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2663 _mesa_error(ctx
, GL_INVALID_VALUE
,
2664 "%s(attribindex=%u >= "
2665 "GL_MAX_VERTEX_ATTRIBS)",
2670 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2671 _mesa_error(ctx
, GL_INVALID_VALUE
,
2672 "%s(bindingindex=%u >= "
2673 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2674 func
, bindingIndex
);
2678 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
2680 _mesa_vertex_attrib_binding(ctx
, vao
,
2681 VERT_ATTRIB_GENERIC(attribIndex
),
2682 VERT_ATTRIB_GENERIC(bindingIndex
), true);
2687 _mesa_VertexAttribBinding_no_error(GLuint attribIndex
, GLuint bindingIndex
)
2689 GET_CURRENT_CONTEXT(ctx
);
2690 _mesa_vertex_attrib_binding(ctx
, ctx
->Array
.VAO
,
2691 VERT_ATTRIB_GENERIC(attribIndex
),
2692 VERT_ATTRIB_GENERIC(bindingIndex
), true);
2697 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2699 GET_CURRENT_CONTEXT(ctx
);
2701 /* The ARB_vertex_attrib_binding spec says:
2703 * "An INVALID_OPERATION error is generated if no vertex array object
2706 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2707 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2708 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2709 "glVertexAttribBinding(No array object bound)");
2713 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2714 attribIndex
, bindingIndex
,
2715 "glVertexAttribBinding");
2720 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj
, GLuint attribIndex
,
2721 GLuint bindingIndex
)
2723 GET_CURRENT_CONTEXT(ctx
);
2725 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2726 _mesa_vertex_attrib_binding(ctx
, vao
,
2727 VERT_ATTRIB_GENERIC(attribIndex
),
2728 VERT_ATTRIB_GENERIC(bindingIndex
), true);
2733 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2735 GET_CURRENT_CONTEXT(ctx
);
2736 struct gl_vertex_array_object
*vao
;
2738 /* The ARB_direct_state_access specification says:
2740 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2741 * if <vaobj> is not [compatibility profile: zero or] the name of an
2742 * existing vertex array object."
2744 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2748 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2749 "glVertexArrayAttribBinding");
2754 vertex_array_binding_divisor(struct gl_context
*ctx
,
2755 struct gl_vertex_array_object
*vao
,
2756 GLuint bindingIndex
, GLuint divisor
,
2759 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2761 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2762 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
2766 /* The ARB_vertex_attrib_binding spec says:
2768 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2769 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2771 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2772 _mesa_error(ctx
, GL_INVALID_VALUE
,
2773 "%s(bindingindex=%u > "
2774 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2775 func
, bindingIndex
);
2779 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2784 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex
, GLuint divisor
)
2786 GET_CURRENT_CONTEXT(ctx
);
2787 vertex_binding_divisor(ctx
, ctx
->Array
.VAO
,
2788 VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2793 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2795 GET_CURRENT_CONTEXT(ctx
);
2797 /* The ARB_vertex_attrib_binding spec says:
2799 * "An INVALID_OPERATION error is generated if no vertex array object
2802 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2803 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2804 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2805 "glVertexBindingDivisor(No array object bound)");
2809 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
2810 bindingIndex
, divisor
,
2811 "glVertexBindingDivisor");
2816 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj
, GLuint bindingIndex
,
2819 GET_CURRENT_CONTEXT(ctx
);
2821 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2822 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2827 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
2830 struct gl_vertex_array_object
*vao
;
2831 GET_CURRENT_CONTEXT(ctx
);
2833 /* The ARB_direct_state_access specification says:
2835 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2836 * if <vaobj> is not [compatibility profile: zero or] the name of an
2837 * existing vertex array object."
2839 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayBindingDivisor");
2843 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
2844 "glVertexArrayBindingDivisor");
2849 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2850 struct gl_array_attributes
*dst
,
2851 const struct gl_array_attributes
*src
)
2853 dst
->Size
= src
->Size
;
2854 dst
->Type
= src
->Type
;
2855 dst
->Format
= src
->Format
;
2856 dst
->BufferBindingIndex
= src
->BufferBindingIndex
;
2857 dst
->RelativeOffset
= src
->RelativeOffset
;
2858 dst
->Format
= src
->Format
;
2859 dst
->Integer
= src
->Integer
;
2860 dst
->Doubles
= src
->Doubles
;
2861 dst
->Normalized
= src
->Normalized
;
2862 dst
->Ptr
= src
->Ptr
;
2863 dst
->Enabled
= src
->Enabled
;
2864 dst
->_ElementSize
= src
->_ElementSize
;
2868 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2869 struct gl_vertex_buffer_binding
*dst
,
2870 const struct gl_vertex_buffer_binding
*src
)
2872 dst
->Offset
= src
->Offset
;
2873 dst
->Stride
= src
->Stride
;
2874 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2875 dst
->_BoundArrays
= src
->_BoundArrays
;
2877 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2881 * Print current vertex object/array info. For debug.
2884 _mesa_print_arrays(struct gl_context
*ctx
)
2886 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2888 fprintf(stderr
, "Array Object %u\n", vao
->Name
);
2891 for (i
= 0; i
< VERT_ATTRIB_MAX
; ++i
) {
2892 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
2893 if (!array
->Enabled
)
2896 const struct gl_vertex_buffer_binding
*binding
=
2897 &vao
->BufferBinding
[array
->BufferBindingIndex
];
2898 const struct gl_buffer_object
*bo
= binding
->BufferObj
;
2900 fprintf(stderr
, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
2901 "Stride=%d, Buffer=%u(Size %lu)\n",
2902 gl_vert_attrib_name((gl_vert_attrib
)i
),
2903 array
->Ptr
, _mesa_enum_to_string(array
->Type
), array
->Size
,
2904 array
->_ElementSize
, binding
->Stride
, bo
->Name
,
2905 (unsigned long) bo
->Size
);
2911 * Initialize vertex array state for given context.
2914 _mesa_init_varray(struct gl_context
*ctx
)
2916 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
2917 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2918 ctx
->Array
._EmptyVAO
= _mesa_new_vao(ctx
, ~0u);
2919 _mesa_reference_vao(ctx
, &ctx
->Array
._DrawVAO
, ctx
->Array
._EmptyVAO
);
2920 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2922 ctx
->Array
.Objects
= _mesa_NewHashTable();
2927 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2930 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2932 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2933 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2934 _mesa_delete_vao(ctx
, vao
);
2939 * Free vertex array state for given context.
2942 _mesa_free_varray_data(struct gl_context
*ctx
)
2944 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2945 _mesa_DeleteHashTable(ctx
->Array
.Objects
);