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.
27 #include <inttypes.h> /* for PRId64 macro */
31 #include "bufferobj.h"
41 #include "main/dispatch.h"
44 /** Used to do error checking for GL_EXT_vertex_array_bgra */
48 /** Used to indicate which GL datatypes are accepted by each of the
49 * glVertex/Color/Attrib/EtcPointer() functions.
51 #define BOOL_BIT (1 << 0)
52 #define BYTE_BIT (1 << 1)
53 #define UNSIGNED_BYTE_BIT (1 << 2)
54 #define SHORT_BIT (1 << 3)
55 #define UNSIGNED_SHORT_BIT (1 << 4)
56 #define INT_BIT (1 << 5)
57 #define UNSIGNED_INT_BIT (1 << 6)
58 #define HALF_BIT (1 << 7)
59 #define FLOAT_BIT (1 << 8)
60 #define DOUBLE_BIT (1 << 9)
61 #define FIXED_ES_BIT (1 << 10)
62 #define FIXED_GL_BIT (1 << 11)
63 #define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12)
64 #define INT_2_10_10_10_REV_BIT (1 << 13)
65 #define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)
66 #define ALL_TYPE_BITS ((1 << 15) - 1)
69 /** Convert GL datatype enum into a <type>_BIT value seen above */
71 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
78 case GL_UNSIGNED_BYTE
:
79 return UNSIGNED_BYTE_BIT
;
82 case GL_UNSIGNED_SHORT
:
83 return UNSIGNED_SHORT_BIT
;
87 return UNSIGNED_INT_BIT
;
89 if (ctx
->Extensions
.ARB_half_float_vertex
)
98 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
99 case GL_UNSIGNED_INT_2_10_10_10_REV
:
100 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
101 case GL_INT_2_10_10_10_REV
:
102 return INT_2_10_10_10_REV_BIT
;
103 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
104 return UNSIGNED_INT_10F_11F_11F_REV_BIT
;
112 * Sets the VertexBinding field in the vertex attribute given by attribIndex.
115 vertex_attrib_binding(struct gl_context
*ctx
, GLuint attribIndex
,
118 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
119 struct gl_vertex_attrib_array
*array
= &vao
->VertexAttrib
[attribIndex
];
121 if (array
->VertexBinding
!= bindingIndex
) {
122 const GLbitfield64 array_bit
= VERT_BIT(attribIndex
);
124 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
126 vao
->VertexBinding
[array
->VertexBinding
]._BoundArrays
&= ~array_bit
;
127 vao
->VertexBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
129 array
->VertexBinding
= bindingIndex
;
131 vao
->NewArrays
|= array_bit
;
137 * Binds a buffer object to the vertex buffer binding point given by index,
138 * and sets the Offset and Stride fields.
141 bind_vertex_buffer(struct gl_context
*ctx
, GLuint index
,
142 struct gl_buffer_object
*vbo
,
143 GLintptr offset
, GLsizei stride
)
145 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
146 struct gl_vertex_buffer_binding
*binding
= &vao
->VertexBinding
[index
];
148 if (binding
->BufferObj
!= vbo
||
149 binding
->Offset
!= offset
||
150 binding
->Stride
!= stride
) {
152 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
154 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
156 binding
->Offset
= offset
;
157 binding
->Stride
= stride
;
159 vao
->NewArrays
|= binding
->_BoundArrays
;
165 * Sets the InstanceDivisor field in the vertex buffer binding point
166 * given by bindingIndex.
169 vertex_binding_divisor(struct gl_context
*ctx
, GLuint bindingIndex
,
172 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
173 struct gl_vertex_buffer_binding
*binding
=
174 &vao
->VertexBinding
[bindingIndex
];
176 if (binding
->InstanceDivisor
!= divisor
) {
177 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
178 binding
->InstanceDivisor
= divisor
;
179 vao
->NewArrays
|= binding
->_BoundArrays
;
185 * Examine the API profile and extensions to determine which types are legal
186 * for vertex arrays. This is called once from update_array_format().
189 get_legal_types_mask(const struct gl_context
*ctx
)
191 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
193 if (_mesa_is_gles(ctx
)) {
194 legalTypesMask
&= ~(FIXED_GL_BIT
|
196 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
198 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
199 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
200 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
201 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
202 * quite as trivial as we'd like because it uses a different enum value
203 * for GL_HALF_FLOAT_OES.
205 if (ctx
->Version
< 30) {
206 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
208 UNSIGNED_INT_2_10_10_10_REV_BIT
|
209 INT_2_10_10_10_REV_BIT
|
214 legalTypesMask
&= ~FIXED_ES_BIT
;
216 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
217 legalTypesMask
&= ~FIXED_GL_BIT
;
219 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
220 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
221 INT_2_10_10_10_REV_BIT
);
223 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
224 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
227 return legalTypesMask
;
232 * Does error checking and updates the format in an attrib array.
234 * Called by update_array() and VertexAttrib*Format().
236 * \param func Name of calling function used for error reporting
237 * \param attrib The index of the attribute array
238 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
239 * \param sizeMin Min allowable size value
240 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
241 * \param size Components per element (1, 2, 3 or 4)
242 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
243 * \param normalized Whether integer types are converted to floats in [-1, 1]
244 * \param integer Integer-valued values (will not be normalized to [-1, 1])
245 * \param relativeOffset Offset of the first element relative to the binding offset.
248 update_array_format(struct gl_context
*ctx
,
250 GLuint attrib
, GLbitfield legalTypesMask
,
251 GLint sizeMin
, GLint sizeMax
,
252 GLint size
, GLenum type
,
253 GLboolean normalized
, GLboolean integer
,
254 GLuint relativeOffset
)
256 struct gl_vertex_attrib_array
*array
;
259 GLenum format
= GL_RGBA
;
261 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
262 /* Compute the LegalTypesMask only once, unless the context API has
263 * changed, in which case we want to compute it again. We can't do this
264 * in _mesa_init_varrays() below because extensions are not yet enabled
267 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
268 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
271 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
273 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
274 /* BGRA ordering is not supported in ES contexts.
279 typeBit
= type_to_bit(ctx
, type
);
280 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
281 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
282 func
, _mesa_lookup_enum_by_nr(type
));
286 /* Do size parameter checking.
287 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
288 * must be handled specially.
290 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
291 sizeMax
== BGRA_OR_4
&&
293 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
295 * "An INVALID_OPERATION error is generated under any of the following
298 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
299 * or UNSIGNED_INT_2_10_10_10_REV;
301 * • size is BGRA and normalized is FALSE;"
303 bool bgra_error
= false;
305 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
306 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
307 type
!= GL_INT_2_10_10_10_REV
&&
308 type
!= GL_UNSIGNED_BYTE
)
310 } else if (type
!= GL_UNSIGNED_BYTE
)
314 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
315 func
, _mesa_lookup_enum_by_nr(type
));
320 _mesa_error(ctx
, GL_INVALID_OPERATION
,
321 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
328 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
329 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
333 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
334 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
335 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
336 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
340 /* The ARB_vertex_attrib_binding_spec says:
342 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
343 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
345 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
346 _mesa_error(ctx
, GL_INVALID_VALUE
,
347 "%s(relativeOffset=%d > "
348 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
349 func
, relativeOffset
);
353 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
354 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
355 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
361 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
362 assert(elementSize
!= -1);
364 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
367 array
->Format
= format
;
368 array
->Normalized
= normalized
;
369 array
->Integer
= integer
;
370 array
->RelativeOffset
= relativeOffset
;
371 array
->_ElementSize
= elementSize
;
373 ctx
->Array
.VAO
->NewArrays
|= VERT_BIT(attrib
);
374 ctx
->NewState
|= _NEW_ARRAY
;
381 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
384 * \param func name of calling function used for error reporting
385 * \param attrib the attribute array index to update
386 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
387 * \param sizeMin min allowable size value
388 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
389 * \param size components per element (1, 2, 3 or 4)
390 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
391 * \param stride stride between elements, in elements
392 * \param normalized are integer types converted to floats in [-1, 1]?
393 * \param integer integer-valued values (will not be normalized to [-1,1])
394 * \param ptr the address (or offset inside VBO) of the array data
397 update_array(struct gl_context
*ctx
,
399 GLuint attrib
, GLbitfield legalTypesMask
,
400 GLint sizeMin
, GLint sizeMax
,
401 GLint size
, GLenum type
, GLsizei stride
,
402 GLboolean normalized
, GLboolean integer
,
405 struct gl_vertex_attrib_array
*array
;
406 GLsizei effectiveStride
;
408 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
410 * "Client vertex arrays - all vertex array attribute pointers must
411 * refer to buffer objects (section 2.9.2). The default vertex array
412 * object (the name zero) is also deprecated. Calling
413 * VertexAttribPointer when no buffer object or no vertex array object
414 * is bound will generate an INVALID_OPERATION error..."
416 * The check for VBOs is handled below.
418 if (ctx
->API
== API_OPENGL_CORE
419 && (ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
)) {
420 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
426 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
430 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
431 stride
> ctx
->Const
.MaxVertexAttribStride
) {
432 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
433 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
437 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
439 * "An INVALID_OPERATION error is generated under any of the following
444 * * any of the *Pointer commands specifying the location and
445 * organization of vertex array data are called while zero is bound
446 * to the ARRAY_BUFFER buffer object binding point (see section
447 * 2.9.6), and the pointer argument is not NULL."
449 if (ptr
!= NULL
&& ctx
->Array
.VAO
->ARBsemantics
&&
450 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
451 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
455 if (!update_array_format(ctx
, func
, attrib
, legalTypesMask
, sizeMin
,
456 sizeMax
, size
, type
, normalized
, integer
, 0)) {
460 /* Reset the vertex attrib binding */
461 vertex_attrib_binding(ctx
, attrib
, attrib
);
463 /* The Stride and Ptr fields are not set by update_array_format() */
464 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
465 array
->Stride
= stride
;
466 array
->Ptr
= (const GLvoid
*) ptr
;
468 /* Update the vertex buffer binding */
469 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
470 bind_vertex_buffer(ctx
, attrib
, ctx
->Array
.ArrayBufferObj
,
471 (GLintptr
) ptr
, effectiveStride
);
476 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
478 GET_CURRENT_CONTEXT(ctx
);
479 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
480 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
481 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
482 DOUBLE_BIT
| HALF_BIT
|
483 UNSIGNED_INT_2_10_10_10_REV_BIT
|
484 INT_2_10_10_10_REV_BIT
);
486 FLUSH_VERTICES(ctx
, 0);
488 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
490 size
, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
495 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
497 GET_CURRENT_CONTEXT(ctx
);
498 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
499 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
500 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
501 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
502 UNSIGNED_INT_2_10_10_10_REV_BIT
|
503 INT_2_10_10_10_REV_BIT
);
505 FLUSH_VERTICES(ctx
, 0);
507 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
509 3, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
514 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
516 GET_CURRENT_CONTEXT(ctx
);
517 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
518 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
519 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
520 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
521 INT_BIT
| UNSIGNED_INT_BIT
|
522 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
523 UNSIGNED_INT_2_10_10_10_REV_BIT
|
524 INT_2_10_10_10_REV_BIT
);
525 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
527 FLUSH_VERTICES(ctx
, 0);
529 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
530 legalTypes
, sizeMin
, BGRA_OR_4
,
531 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
536 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
538 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
539 GET_CURRENT_CONTEXT(ctx
);
541 FLUSH_VERTICES(ctx
, 0);
543 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
545 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
550 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
552 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
553 FLOAT_BIT
| DOUBLE_BIT
);
554 GET_CURRENT_CONTEXT(ctx
);
556 FLUSH_VERTICES(ctx
, 0);
558 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
560 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
565 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
566 GLsizei stride
, const GLvoid
*ptr
)
568 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
569 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
570 INT_BIT
| UNSIGNED_INT_BIT
|
571 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
572 UNSIGNED_INT_2_10_10_10_REV_BIT
|
573 INT_2_10_10_10_REV_BIT
);
574 GET_CURRENT_CONTEXT(ctx
);
576 FLUSH_VERTICES(ctx
, 0);
578 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
579 legalTypes
, 3, BGRA_OR_4
,
580 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
585 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
588 GET_CURRENT_CONTEXT(ctx
);
589 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
590 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
591 : (SHORT_BIT
| INT_BIT
|
592 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
593 UNSIGNED_INT_2_10_10_10_REV_BIT
|
594 INT_2_10_10_10_REV_BIT
);
595 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
596 const GLuint unit
= ctx
->Array
.ActiveTexture
;
598 FLUSH_VERTICES(ctx
, 0);
600 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
601 legalTypes
, sizeMin
, 4,
602 size
, type
, stride
, GL_FALSE
, GL_FALSE
,
608 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
610 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
611 /* this is the same type that glEdgeFlag uses */
612 const GLboolean integer
= GL_FALSE
;
613 GET_CURRENT_CONTEXT(ctx
);
615 FLUSH_VERTICES(ctx
, 0);
617 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
619 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, ptr
);
624 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
626 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
627 GET_CURRENT_CONTEXT(ctx
);
629 FLUSH_VERTICES(ctx
, 0);
631 if (ctx
->API
!= API_OPENGLES
) {
632 _mesa_error(ctx
, GL_INVALID_OPERATION
,
633 "glPointSizePointer(ES 1.x only)");
637 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
639 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
644 * Set a generic vertex attribute array.
645 * Note that these arrays DO NOT alias the conventional GL vertex arrays
646 * (position, normal, color, fog, texcoord, etc).
649 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
650 GLboolean normalized
,
651 GLsizei stride
, const GLvoid
*ptr
)
653 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
654 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
655 INT_BIT
| UNSIGNED_INT_BIT
|
656 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
657 FIXED_ES_BIT
| FIXED_GL_BIT
|
658 UNSIGNED_INT_2_10_10_10_REV_BIT
|
659 INT_2_10_10_10_REV_BIT
|
660 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
661 GET_CURRENT_CONTEXT(ctx
);
663 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
664 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
668 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
669 legalTypes
, 1, BGRA_OR_4
,
670 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
675 * GL_EXT_gpu_shader4 / GL 3.0.
676 * Set an integer-valued vertex attribute array.
677 * Note that these arrays DO NOT alias the conventional GL vertex arrays
678 * (position, normal, color, fog, texcoord, etc).
681 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
682 GLsizei stride
, const GLvoid
*ptr
)
684 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
685 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
686 INT_BIT
| UNSIGNED_INT_BIT
);
687 const GLboolean normalized
= GL_FALSE
;
688 const GLboolean integer
= GL_TRUE
;
689 GET_CURRENT_CONTEXT(ctx
);
691 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
692 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
696 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
698 size
, type
, stride
, normalized
, integer
, ptr
);
704 _mesa_EnableVertexAttribArray(GLuint index
)
706 struct gl_vertex_array_object
*vao
;
707 GET_CURRENT_CONTEXT(ctx
);
709 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
710 _mesa_error(ctx
, GL_INVALID_VALUE
,
711 "glEnableVertexAttribArrayARB(index)");
715 vao
= ctx
->Array
.VAO
;
717 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(vao
->VertexAttrib
));
719 if (!vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
720 /* was disabled, now being enabled */
721 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
722 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
723 vao
->_Enabled
|= VERT_BIT_GENERIC(index
);
724 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
730 _mesa_DisableVertexAttribArray(GLuint index
)
732 struct gl_vertex_array_object
*vao
;
733 GET_CURRENT_CONTEXT(ctx
);
735 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
736 _mesa_error(ctx
, GL_INVALID_VALUE
,
737 "glDisableVertexAttribArrayARB(index)");
741 vao
= ctx
->Array
.VAO
;
743 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(vao
->VertexAttrib
));
745 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
746 /* was enabled, now being disabled */
747 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
748 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
749 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
750 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
756 * Return info for a vertex attribute array (no alias with legacy
757 * vertex attributes (pos, normal, color, etc)). This function does
758 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
761 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
764 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
765 const struct gl_vertex_attrib_array
*array
;
767 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
768 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
772 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(vao
->VertexAttrib
));
774 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
777 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
778 return array
->Enabled
;
779 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
780 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
781 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
782 return array
->Stride
;
783 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
785 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
786 return array
->Normalized
;
787 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
788 return vao
->VertexBinding
[array
->VertexBinding
].BufferObj
->Name
;
789 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
790 if ((_mesa_is_desktop_gl(ctx
)
791 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
792 || _mesa_is_gles3(ctx
)) {
793 return array
->Integer
;
796 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
797 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
798 || _mesa_is_gles3(ctx
)) {
799 return vao
->VertexBinding
[array
->VertexBinding
].InstanceDivisor
;
802 case GL_VERTEX_ATTRIB_BINDING
:
803 if (_mesa_is_desktop_gl(ctx
)) {
804 return array
->VertexBinding
- VERT_ATTRIB_GENERIC0
;
807 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
808 if (_mesa_is_desktop_gl(ctx
)) {
809 return array
->RelativeOffset
;
817 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
822 static const GLfloat
*
823 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
826 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
827 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
831 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
832 _mesa_error(ctx
, GL_INVALID_VALUE
,
833 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
837 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.VAO
->VertexAttrib
));
839 FLUSH_CURRENT(ctx
, 0);
840 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
844 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
846 GET_CURRENT_CONTEXT(ctx
);
848 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
849 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
855 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
856 "glGetVertexAttribfv");
862 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
864 GET_CURRENT_CONTEXT(ctx
);
866 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
867 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
869 params
[0] = (GLdouble
) v
[0];
870 params
[1] = (GLdouble
) v
[1];
871 params
[2] = (GLdouble
) v
[2];
872 params
[3] = (GLdouble
) v
[3];
876 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
877 "glGetVertexAttribdv");
883 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
885 GET_CURRENT_CONTEXT(ctx
);
887 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
888 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
890 /* XXX should floats in[0,1] be scaled to full int range? */
891 params
[0] = (GLint
) v
[0];
892 params
[1] = (GLint
) v
[1];
893 params
[2] = (GLint
) v
[2];
894 params
[3] = (GLint
) v
[3];
898 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
899 "glGetVertexAttribiv");
906 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
908 GET_CURRENT_CONTEXT(ctx
);
910 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
911 const GLint
*v
= (const GLint
*)
912 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
918 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
919 "glGetVertexAttribIiv");
926 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
928 GET_CURRENT_CONTEXT(ctx
);
930 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
931 const GLuint
*v
= (const GLuint
*)
932 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
938 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
939 "glGetVertexAttribIuiv");
945 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
947 GET_CURRENT_CONTEXT(ctx
);
949 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
950 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
954 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
955 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
959 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.VAO
->VertexAttrib
));
961 *pointer
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
966 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
967 GLsizei count
, const GLvoid
*ptr
)
970 _mesa_VertexPointer(size
, type
, stride
, ptr
);
975 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
979 _mesa_NormalPointer(type
, stride
, ptr
);
984 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
988 _mesa_ColorPointer(size
, type
, stride
, ptr
);
993 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
997 _mesa_IndexPointer(type
, stride
, ptr
);
1002 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1003 GLsizei count
, const GLvoid
*ptr
)
1006 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1011 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1014 _mesa_EdgeFlagPointer(stride
, ptr
);
1019 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1021 GET_CURRENT_CONTEXT(ctx
);
1022 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1023 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1024 GLenum ctype
= 0; /* color type */
1025 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1026 const GLint toffset
= 0; /* always zero */
1027 GLint defstride
; /* default stride */
1030 FLUSH_VERTICES(ctx
, 0);
1032 f
= sizeof(GLfloat
);
1033 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1036 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1042 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1043 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1048 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1049 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1054 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1055 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1056 ctype
= GL_UNSIGNED_BYTE
;
1059 defstride
= c
+ 2*f
;
1062 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1063 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1064 ctype
= GL_UNSIGNED_BYTE
;
1067 defstride
= c
+ 3*f
;
1070 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1071 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1078 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1079 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1084 case GL_C4F_N3F_V3F
:
1085 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1086 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1094 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1095 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1100 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1101 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1105 case GL_T2F_C4UB_V3F
:
1106 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1107 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1108 ctype
= GL_UNSIGNED_BYTE
;
1113 case GL_T2F_C3F_V3F
:
1114 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1115 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1121 case GL_T2F_N3F_V3F
:
1122 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1123 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1128 case GL_T2F_C4F_N3F_V3F
:
1129 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1130 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1137 case GL_T4F_C4F_N3F_V4F
:
1138 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1139 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1147 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1155 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1156 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1157 /* XXX also disable secondary color and generic arrays? */
1161 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1162 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1163 (GLubyte
*) pointer
+ toffset
);
1166 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1171 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1172 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1173 (GLubyte
*) pointer
+ coffset
);
1176 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1182 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1183 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1186 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1190 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1191 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1192 (GLubyte
*) pointer
+ voffset
);
1197 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1199 GET_CURRENT_CONTEXT(ctx
);
1201 FLUSH_VERTICES(ctx
, 0);
1203 if (MESA_VERBOSE
& VERBOSE_API
)
1204 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1207 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1211 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1214 if (ctx
->Array
.LockCount
!= 0) {
1215 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1219 ctx
->Array
.LockFirst
= first
;
1220 ctx
->Array
.LockCount
= count
;
1222 ctx
->NewState
|= _NEW_ARRAY
;
1227 _mesa_UnlockArraysEXT( void )
1229 GET_CURRENT_CONTEXT(ctx
);
1231 FLUSH_VERTICES(ctx
, 0);
1233 if (MESA_VERBOSE
& VERBOSE_API
)
1234 _mesa_debug(ctx
, "glUnlockArrays\n");
1236 if (ctx
->Array
.LockCount
== 0) {
1237 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1241 ctx
->Array
.LockFirst
= 0;
1242 ctx
->Array
.LockCount
= 0;
1243 ctx
->NewState
|= _NEW_ARRAY
;
1247 /* GL_EXT_multi_draw_arrays */
1249 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1250 const GLsizei
*count
, GLsizei primcount
)
1252 GET_CURRENT_CONTEXT(ctx
);
1255 FLUSH_VERTICES(ctx
, 0);
1257 for (i
= 0; i
< primcount
; i
++) {
1259 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1265 /* GL_IBM_multimode_draw_arrays */
1267 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1268 const GLsizei
* count
,
1269 GLsizei primcount
, GLint modestride
)
1271 GET_CURRENT_CONTEXT(ctx
);
1274 FLUSH_VERTICES(ctx
, 0);
1276 for ( i
= 0 ; i
< primcount
; i
++ ) {
1277 if ( count
[i
] > 0 ) {
1278 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1279 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1285 /* GL_IBM_multimode_draw_arrays */
1287 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1288 GLenum type
, const GLvoid
* const * indices
,
1289 GLsizei primcount
, GLint modestride
)
1291 GET_CURRENT_CONTEXT(ctx
);
1294 FLUSH_VERTICES(ctx
, 0);
1296 /* XXX not sure about ARB_vertex_buffer_object handling here */
1298 for ( i
= 0 ; i
< primcount
; i
++ ) {
1299 if ( count
[i
] > 0 ) {
1300 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1301 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1309 * GL_NV_primitive_restart and GL 3.1
1312 _mesa_PrimitiveRestartIndex(GLuint index
)
1314 GET_CURRENT_CONTEXT(ctx
);
1316 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1317 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1321 if (ctx
->Array
.RestartIndex
!= index
) {
1322 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1323 ctx
->Array
.RestartIndex
= index
;
1329 * See GL_ARB_instanced_arrays.
1330 * Note that the instance divisor only applies to generic arrays, not
1331 * the legacy vertex arrays.
1334 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1336 GET_CURRENT_CONTEXT(ctx
);
1338 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1340 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1341 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1345 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1346 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1351 ASSERT(genericIndex
< Elements(ctx
->Array
.VAO
->VertexAttrib
));
1353 /* The ARB_vertex_attrib_binding spec says:
1357 * void VertexAttribDivisor(uint index, uint divisor);
1359 * is equivalent to (assuming no errors are generated):
1361 * VertexAttribBinding(index, index);
1362 * VertexBindingDivisor(index, divisor);"
1364 vertex_attrib_binding(ctx
, genericIndex
, genericIndex
);
1365 vertex_binding_divisor(ctx
, genericIndex
, divisor
);
1370 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1372 /* From the OpenGL 4.3 core specification, page 302:
1373 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1374 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1377 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1379 case GL_UNSIGNED_BYTE
:
1381 case GL_UNSIGNED_SHORT
:
1383 case GL_UNSIGNED_INT
:
1386 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1390 return ctx
->Array
.RestartIndex
;
1395 * GL_ARB_vertex_attrib_binding
1398 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1401 GET_CURRENT_CONTEXT(ctx
);
1402 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1403 struct gl_buffer_object
*vbo
;
1405 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1407 /* The ARB_vertex_attrib_binding spec says:
1409 * "An INVALID_OPERATION error is generated if no vertex array object
1412 if (ctx
->API
== API_OPENGL_CORE
&&
1413 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1414 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1415 "glBindVertexBuffer(No array object bound)");
1419 /* The ARB_vertex_attrib_binding spec says:
1421 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1422 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1424 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1425 _mesa_error(ctx
, GL_INVALID_VALUE
,
1426 "glBindVertexBuffer(bindingindex=%u > "
1427 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1432 /* The ARB_vertex_attrib_binding spec says:
1434 * "The error INVALID_VALUE is generated if <stride> or <offset>
1438 _mesa_error(ctx
, GL_INVALID_VALUE
,
1439 "glBindVertexBuffer(offset=%" PRId64
" < 0)",
1445 _mesa_error(ctx
, GL_INVALID_VALUE
,
1446 "glBindVertexBuffer(stride=%d < 0)", stride
);
1450 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1451 stride
> ctx
->Const
.MaxVertexAttribStride
) {
1452 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindVertexBuffer(stride=%d > "
1453 "GL_MAX_VERTEX_ATTRIB_STRIDE)", stride
);
1457 if (buffer
== vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1458 vbo
= vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1459 } else if (buffer
!= 0) {
1460 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1462 /* From the GL_ARB_vertex_attrib_array spec:
1464 * "[Core profile only:]
1465 * An INVALID_OPERATION error is generated if buffer is not zero or a
1466 * name returned from a previous call to GenBuffers, or if such a name
1467 * has since been deleted with DeleteBuffers.
1469 * Otherwise, we fall back to the same compat profile behavior as other
1470 * object references (automatically gen it).
1472 if (!_mesa_handle_bind_buffer_gen(ctx
, GL_ARRAY_BUFFER
, buffer
,
1473 &vbo
, "glBindVertexBuffer"))
1476 /* The ARB_vertex_attrib_binding spec says:
1478 * "If <buffer> is zero, any buffer object attached to this
1479 * bindpoint is detached."
1481 vbo
= ctx
->Shared
->NullBufferObj
;
1484 bind_vertex_buffer(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
),
1485 vbo
, offset
, stride
);
1490 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1491 const GLintptr
*offsets
, const GLsizei
*strides
)
1493 GET_CURRENT_CONTEXT(ctx
);
1494 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1497 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1499 /* The ARB_vertex_attrib_binding spec says:
1501 * "An INVALID_OPERATION error is generated if no
1502 * vertex array object is bound."
1504 if (ctx
->API
== API_OPENGL_CORE
&&
1505 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1506 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1507 "glBindVertexBuffers(No array object bound)");
1511 /* The ARB_multi_bind spec says:
1513 * "An INVALID_OPERATION error is generated if <first> + <count>
1514 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1516 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1517 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1518 "glBindVertexBuffers(first=%u + count=%d > the value of "
1519 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1520 first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1526 * The ARB_multi_bind spec says:
1528 * "If <buffers> is NULL, each affected vertex buffer binding point
1529 * from <first> through <first>+<count>-1 will be reset to have no
1530 * bound buffer object. In this case, the offsets and strides
1531 * associated with the binding points are set to default values,
1532 * ignoring <offsets> and <strides>."
1534 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1536 for (i
= 0; i
< count
; i
++)
1537 bind_vertex_buffer(ctx
, VERT_ATTRIB_GENERIC(first
+ i
), vbo
, 0, 16);
1542 /* Note that the error semantics for multi-bind commands differ from
1543 * those of other GL commands.
1545 * The Issues section in the ARB_multi_bind spec says:
1547 * "(11) Typically, OpenGL specifies that if an error is generated by
1548 * a command, that command has no effect. This is somewhat
1549 * unfortunate for multi-bind commands, because it would require
1550 * a first pass to scan the entire list of bound objects for
1551 * errors and then a second pass to actually perform the
1552 * bindings. Should we have different error semantics?
1554 * RESOLVED: Yes. In this specification, when the parameters for
1555 * one of the <count> binding points are invalid, that binding
1556 * point is not updated and an error will be generated. However,
1557 * other binding points in the same command will be updated if
1558 * their parameters are valid and no other error occurs."
1561 _mesa_begin_bufferobj_lookups(ctx
);
1563 for (i
= 0; i
< count
; i
++) {
1564 struct gl_buffer_object
*vbo
;
1566 /* The ARB_multi_bind spec says:
1568 * "An INVALID_VALUE error is generated if any value in
1569 * <offsets> or <strides> is negative (per binding)."
1571 if (offsets
[i
] < 0) {
1572 _mesa_error(ctx
, GL_INVALID_VALUE
,
1573 "glBindVertexBuffers(offsets[%u]=%" PRId64
" < 0)",
1574 i
, (int64_t) offsets
[i
]);
1578 if (strides
[i
] < 0) {
1579 _mesa_error(ctx
, GL_INVALID_VALUE
,
1580 "glBindVertexBuffers(strides[%u]=%d < 0)",
1585 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1586 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
1587 _mesa_error(ctx
, GL_INVALID_VALUE
,
1588 "glBindVertexBuffers(strides[%u]=%d > "
1589 "GL_MAX_VERTEX_ATTRIB_STRIDE)", i
, strides
[i
]);
1594 struct gl_vertex_buffer_binding
*binding
=
1595 &vao
->VertexBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1597 if (buffers
[i
] == binding
->BufferObj
->Name
)
1598 vbo
= binding
->BufferObj
;
1600 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
1601 "glBindVertexBuffers");
1606 vbo
= ctx
->Shared
->NullBufferObj
;
1609 bind_vertex_buffer(ctx
, VERT_ATTRIB_GENERIC(first
+ i
), vbo
,
1610 offsets
[i
], strides
[i
]);
1613 _mesa_end_bufferobj_lookups(ctx
);
1618 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1619 GLboolean normalized
, GLuint relativeOffset
)
1621 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1622 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1623 INT_BIT
| UNSIGNED_INT_BIT
|
1624 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1626 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1627 INT_2_10_10_10_REV_BIT
|
1628 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1630 GET_CURRENT_CONTEXT(ctx
);
1631 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1633 /* The ARB_vertex_attrib_binding spec says:
1635 * "An INVALID_OPERATION error is generated under any of the following
1637 * - if no vertex array object is currently bound (see section 2.10);
1640 if (ctx
->API
== API_OPENGL_CORE
&&
1641 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1642 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1643 "glVertexAttribFormat(No array object bound)");
1647 /* The ARB_vertex_attrib_binding spec says:
1649 * "The error INVALID_VALUE is generated if index is greater than or equal
1650 * to the value of MAX_VERTEX_ATTRIBS."
1652 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1653 _mesa_error(ctx
, GL_INVALID_VALUE
,
1654 "glVertexAttribFormat(attribindex=%u > "
1655 "GL_MAX_VERTEX_ATTRIBS)",
1660 FLUSH_VERTICES(ctx
, 0);
1662 update_array_format(ctx
, "glVertexAttribFormat",
1663 VERT_ATTRIB_GENERIC(attribIndex
),
1664 legalTypes
, 1, BGRA_OR_4
, size
, type
, normalized
,
1665 GL_FALSE
, relativeOffset
);
1670 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1671 GLuint relativeOffset
)
1673 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1674 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1675 INT_BIT
| UNSIGNED_INT_BIT
);
1677 GET_CURRENT_CONTEXT(ctx
);
1678 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1680 /* The ARB_vertex_attrib_binding spec says:
1682 * "An INVALID_OPERATION error is generated under any of the following
1684 * - if no vertex array object is currently bound (see section 2.10);
1687 if (ctx
->API
== API_OPENGL_CORE
&&
1688 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1689 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1690 "glVertexAttribIFormat(No array object bound)");
1694 /* The ARB_vertex_attrib_binding spec says:
1696 * "The error INVALID_VALUE is generated if index is greater than
1697 * or equal to the value of MAX_VERTEX_ATTRIBS."
1699 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1700 _mesa_error(ctx
, GL_INVALID_VALUE
,
1701 "glVertexAttribIFormat(attribindex=%u > "
1702 "GL_MAX_VERTEX_ATTRIBS)",
1707 FLUSH_VERTICES(ctx
, 0);
1709 update_array_format(ctx
, "glVertexAttribIFormat",
1710 VERT_ATTRIB_GENERIC(attribIndex
),
1711 legalTypes
, 1, 4, size
, type
, GL_FALSE
, GL_TRUE
,
1717 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1718 GLuint relativeOffset
)
1720 const GLbitfield legalTypes
= DOUBLE_BIT
;
1722 GET_CURRENT_CONTEXT(ctx
);
1723 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1725 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
1727 * "An INVALID_OPERATION error is generated under any of the following
1729 * • if no vertex array object is currently bound (see section 10.4);
1732 * This language is missing from the extension spec, but we assume
1733 * that this is an oversight.
1735 if (ctx
->API
== API_OPENGL_CORE
&&
1736 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1737 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1738 "glVertexAttribLFormat(No array object bound)");
1742 /* The ARB_vertex_attrib_binding spec says:
1744 * "The error INVALID_VALUE is generated if <attribindex> is greater than
1745 * or equal to the value of MAX_VERTEX_ATTRIBS."
1747 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1748 _mesa_error(ctx
, GL_INVALID_VALUE
,
1749 "glVertexAttribLFormat(attribindex=%u > "
1750 "GL_MAX_VERTEX_ATTRIBS)",
1755 FLUSH_VERTICES(ctx
, 0);
1757 update_array_format(ctx
, "glVertexAttribLFormat",
1758 VERT_ATTRIB_GENERIC(attribIndex
),
1759 legalTypes
, 1, 4, size
, type
, GL_FALSE
, GL_FALSE
,
1765 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
1767 GET_CURRENT_CONTEXT(ctx
);
1768 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1770 /* The ARB_vertex_attrib_binding spec says:
1772 * "An INVALID_OPERATION error is generated if no vertex array object
1775 if (ctx
->API
== API_OPENGL_CORE
&&
1776 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1777 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1778 "glVertexAttribBinding(No array object bound)");
1782 /* The ARB_vertex_attrib_binding spec says:
1784 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1785 * <bindingindex> must be less than the value of
1786 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1789 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1790 _mesa_error(ctx
, GL_INVALID_VALUE
,
1791 "glVertexAttribBinding(attribindex=%u >= "
1792 "GL_MAX_VERTEX_ATTRIBS)",
1797 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1798 _mesa_error(ctx
, GL_INVALID_VALUE
,
1799 "glVertexAttribBinding(bindingindex=%u >= "
1800 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1805 ASSERT(VERT_ATTRIB_GENERIC(attribIndex
) <
1806 Elements(ctx
->Array
.VAO
->VertexAttrib
));
1808 vertex_attrib_binding(ctx
, VERT_ATTRIB_GENERIC(attribIndex
),
1809 VERT_ATTRIB_GENERIC(bindingIndex
));
1814 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
1816 GET_CURRENT_CONTEXT(ctx
);
1817 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1819 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1820 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexBindingDivisor()");
1824 /* The ARB_vertex_attrib_binding spec says:
1826 * "An INVALID_OPERATION error is generated if no vertex array object
1829 if (ctx
->API
== API_OPENGL_CORE
&&
1830 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1831 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1832 "glVertexBindingDivisor(No array object bound)");
1836 /* The ARB_vertex_attrib_binding spec says:
1838 * "An INVALID_VALUE error is generated if <bindingindex> is greater
1839 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
1841 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1842 _mesa_error(ctx
, GL_INVALID_VALUE
,
1843 "glVertexBindingDivisor(bindingindex=%u > "
1844 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1849 vertex_binding_divisor(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
1854 * Copy one client vertex array to another.
1857 _mesa_copy_client_array(struct gl_context
*ctx
,
1858 struct gl_client_array
*dst
,
1859 struct gl_client_array
*src
)
1861 dst
->Size
= src
->Size
;
1862 dst
->Type
= src
->Type
;
1863 dst
->Format
= src
->Format
;
1864 dst
->Stride
= src
->Stride
;
1865 dst
->StrideB
= src
->StrideB
;
1866 dst
->Ptr
= src
->Ptr
;
1867 dst
->Enabled
= src
->Enabled
;
1868 dst
->Normalized
= src
->Normalized
;
1869 dst
->Integer
= src
->Integer
;
1870 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1871 dst
->_ElementSize
= src
->_ElementSize
;
1872 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1876 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
1877 struct gl_vertex_attrib_array
*dst
,
1878 const struct gl_vertex_attrib_array
*src
)
1880 dst
->Size
= src
->Size
;
1881 dst
->Type
= src
->Type
;
1882 dst
->Format
= src
->Format
;
1883 dst
->VertexBinding
= src
->VertexBinding
;
1884 dst
->RelativeOffset
= src
->RelativeOffset
;
1885 dst
->Format
= src
->Format
;
1886 dst
->Integer
= src
->Integer
;
1887 dst
->Normalized
= src
->Normalized
;
1888 dst
->Ptr
= src
->Ptr
;
1889 dst
->Enabled
= src
->Enabled
;
1890 dst
->_ElementSize
= src
->_ElementSize
;
1894 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
1895 struct gl_vertex_buffer_binding
*dst
,
1896 const struct gl_vertex_buffer_binding
*src
)
1898 dst
->Offset
= src
->Offset
;
1899 dst
->Stride
= src
->Stride
;
1900 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1901 dst
->_BoundArrays
= src
->_BoundArrays
;
1903 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1907 * Print vertex array's fields.
1910 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1913 fprintf(stderr
, " %s[%d]: ", name
, index
);
1915 fprintf(stderr
, " %s: ", name
);
1916 fprintf(stderr
, "Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
1917 array
->Ptr
, array
->Type
, array
->Size
,
1918 array
->_ElementSize
, array
->StrideB
,
1919 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
);
1924 * Print current vertex object/array info. For debug.
1927 _mesa_print_arrays(struct gl_context
*ctx
)
1929 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1932 printf("Array Object %u\n", vao
->Name
);
1933 if (vao
->_VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
1934 print_array("Vertex", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_POS
]);
1935 if (vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
1936 print_array("Normal", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
]);
1937 if (vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
1938 print_array("Color", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
]);
1939 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
1940 if (vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
1941 print_array("TexCoord", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
1942 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
1943 if (vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
1944 print_array("Attrib", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
1949 * Initialize vertex array state for given context.
1952 _mesa_init_varray(struct gl_context
*ctx
)
1954 ctx
->Array
.DefaultVAO
= ctx
->Driver
.NewArrayObject(ctx
, 0);
1955 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
1956 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1958 ctx
->Array
.Objects
= _mesa_NewHashTable();
1963 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1966 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1968 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
1969 struct gl_context
*ctx
= (struct gl_context
*) userData
;
1970 _mesa_delete_vao(ctx
, vao
);
1975 * Free vertex array state for given context.
1978 _mesa_free_varray_data(struct gl_context
*ctx
)
1980 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1981 _mesa_DeleteHashTable(ctx
->Array
.Objects
);