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) {
262 /* One-time initialization. We can't do this in _mesa_init_varrays()
263 * below because extensions are not yet enabled at that point.
265 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
268 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
270 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
271 /* BGRA ordering is not supported in ES contexts.
276 typeBit
= type_to_bit(ctx
, type
);
277 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
278 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
279 func
, _mesa_lookup_enum_by_nr(type
));
283 /* Do size parameter checking.
284 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
285 * must be handled specially.
287 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
288 sizeMax
== BGRA_OR_4
&&
290 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
292 * "An INVALID_OPERATION error is generated under any of the following
295 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
296 * or UNSIGNED_INT_2_10_10_10_REV;
298 * • size is BGRA and normalized is FALSE;"
300 bool bgra_error
= false;
302 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
303 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
304 type
!= GL_INT_2_10_10_10_REV
&&
305 type
!= GL_UNSIGNED_BYTE
)
307 } else if (type
!= GL_UNSIGNED_BYTE
)
311 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
312 func
, _mesa_lookup_enum_by_nr(type
));
317 _mesa_error(ctx
, GL_INVALID_OPERATION
,
318 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
325 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
326 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
330 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
331 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
332 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
333 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
337 /* The ARB_vertex_attrib_binding_spec says:
339 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
340 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
342 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
343 _mesa_error(ctx
, GL_INVALID_VALUE
,
344 "%s(relativeOffset=%d > "
345 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
346 func
, relativeOffset
);
350 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
351 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
352 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
358 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
359 assert(elementSize
!= -1);
361 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
364 array
->Format
= format
;
365 array
->Normalized
= normalized
;
366 array
->Integer
= integer
;
367 array
->RelativeOffset
= relativeOffset
;
368 array
->_ElementSize
= elementSize
;
370 ctx
->Array
.VAO
->NewArrays
|= VERT_BIT(attrib
);
371 ctx
->NewState
|= _NEW_ARRAY
;
378 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
381 * \param func name of calling function used for error reporting
382 * \param attrib the attribute array index to update
383 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
384 * \param sizeMin min allowable size value
385 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
386 * \param size components per element (1, 2, 3 or 4)
387 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
388 * \param stride stride between elements, in elements
389 * \param normalized are integer types converted to floats in [-1, 1]?
390 * \param integer integer-valued values (will not be normalized to [-1,1])
391 * \param ptr the address (or offset inside VBO) of the array data
394 update_array(struct gl_context
*ctx
,
396 GLuint attrib
, GLbitfield legalTypesMask
,
397 GLint sizeMin
, GLint sizeMax
,
398 GLint size
, GLenum type
, GLsizei stride
,
399 GLboolean normalized
, GLboolean integer
,
402 struct gl_vertex_attrib_array
*array
;
403 GLsizei effectiveStride
;
405 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
407 * "Client vertex arrays - all vertex array attribute pointers must
408 * refer to buffer objects (section 2.9.2). The default vertex array
409 * object (the name zero) is also deprecated. Calling
410 * VertexAttribPointer when no buffer object or no vertex array object
411 * is bound will generate an INVALID_OPERATION error..."
413 * The check for VBOs is handled below.
415 if (ctx
->API
== API_OPENGL_CORE
416 && (ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
)) {
417 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
423 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
427 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
428 stride
> ctx
->Const
.MaxVertexAttribStride
) {
429 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
430 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
434 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
436 * "An INVALID_OPERATION error is generated under any of the following
441 * * any of the *Pointer commands specifying the location and
442 * organization of vertex array data are called while zero is bound
443 * to the ARRAY_BUFFER buffer object binding point (see section
444 * 2.9.6), and the pointer argument is not NULL."
446 if (ptr
!= NULL
&& ctx
->Array
.VAO
->ARBsemantics
&&
447 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
448 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
452 if (!update_array_format(ctx
, func
, attrib
, legalTypesMask
, sizeMin
,
453 sizeMax
, size
, type
, normalized
, integer
, 0)) {
457 /* Reset the vertex attrib binding */
458 vertex_attrib_binding(ctx
, attrib
, attrib
);
460 /* The Stride and Ptr fields are not set by update_array_format() */
461 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
462 array
->Stride
= stride
;
463 array
->Ptr
= (const GLvoid
*) ptr
;
465 /* Update the vertex buffer binding */
466 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
467 bind_vertex_buffer(ctx
, attrib
, ctx
->Array
.ArrayBufferObj
,
468 (GLintptr
) ptr
, effectiveStride
);
473 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
475 GET_CURRENT_CONTEXT(ctx
);
476 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
477 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
478 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
479 DOUBLE_BIT
| HALF_BIT
|
480 UNSIGNED_INT_2_10_10_10_REV_BIT
|
481 INT_2_10_10_10_REV_BIT
);
483 FLUSH_VERTICES(ctx
, 0);
485 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
487 size
, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
492 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
494 GET_CURRENT_CONTEXT(ctx
);
495 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
496 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
497 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
498 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
499 UNSIGNED_INT_2_10_10_10_REV_BIT
|
500 INT_2_10_10_10_REV_BIT
);
502 FLUSH_VERTICES(ctx
, 0);
504 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
506 3, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
511 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
513 GET_CURRENT_CONTEXT(ctx
);
514 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
515 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
516 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
517 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
518 INT_BIT
| UNSIGNED_INT_BIT
|
519 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
520 UNSIGNED_INT_2_10_10_10_REV_BIT
|
521 INT_2_10_10_10_REV_BIT
);
522 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
524 FLUSH_VERTICES(ctx
, 0);
526 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
527 legalTypes
, sizeMin
, BGRA_OR_4
,
528 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
533 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
535 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
536 GET_CURRENT_CONTEXT(ctx
);
538 FLUSH_VERTICES(ctx
, 0);
540 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
542 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
547 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
549 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
550 FLOAT_BIT
| DOUBLE_BIT
);
551 GET_CURRENT_CONTEXT(ctx
);
553 FLUSH_VERTICES(ctx
, 0);
555 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
557 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
562 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
563 GLsizei stride
, const GLvoid
*ptr
)
565 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
566 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
567 INT_BIT
| UNSIGNED_INT_BIT
|
568 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
569 UNSIGNED_INT_2_10_10_10_REV_BIT
|
570 INT_2_10_10_10_REV_BIT
);
571 GET_CURRENT_CONTEXT(ctx
);
573 FLUSH_VERTICES(ctx
, 0);
575 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
576 legalTypes
, 3, BGRA_OR_4
,
577 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
582 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
585 GET_CURRENT_CONTEXT(ctx
);
586 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
587 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
588 : (SHORT_BIT
| INT_BIT
|
589 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
590 UNSIGNED_INT_2_10_10_10_REV_BIT
|
591 INT_2_10_10_10_REV_BIT
);
592 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
593 const GLuint unit
= ctx
->Array
.ActiveTexture
;
595 FLUSH_VERTICES(ctx
, 0);
597 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
598 legalTypes
, sizeMin
, 4,
599 size
, type
, stride
, GL_FALSE
, GL_FALSE
,
605 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
607 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
608 /* this is the same type that glEdgeFlag uses */
609 const GLboolean integer
= GL_FALSE
;
610 GET_CURRENT_CONTEXT(ctx
);
612 FLUSH_VERTICES(ctx
, 0);
614 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
616 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, ptr
);
621 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
623 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
624 GET_CURRENT_CONTEXT(ctx
);
626 FLUSH_VERTICES(ctx
, 0);
628 if (ctx
->API
!= API_OPENGLES
) {
629 _mesa_error(ctx
, GL_INVALID_OPERATION
,
630 "glPointSizePointer(ES 1.x only)");
634 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
636 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
641 * Set a generic vertex attribute array.
642 * Note that these arrays DO NOT alias the conventional GL vertex arrays
643 * (position, normal, color, fog, texcoord, etc).
646 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
647 GLboolean normalized
,
648 GLsizei stride
, const GLvoid
*ptr
)
650 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
651 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
652 INT_BIT
| UNSIGNED_INT_BIT
|
653 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
654 FIXED_ES_BIT
| FIXED_GL_BIT
|
655 UNSIGNED_INT_2_10_10_10_REV_BIT
|
656 INT_2_10_10_10_REV_BIT
|
657 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
658 GET_CURRENT_CONTEXT(ctx
);
660 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
661 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
665 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
666 legalTypes
, 1, BGRA_OR_4
,
667 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
672 * GL_EXT_gpu_shader4 / GL 3.0.
673 * Set an integer-valued vertex attribute array.
674 * Note that these arrays DO NOT alias the conventional GL vertex arrays
675 * (position, normal, color, fog, texcoord, etc).
678 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
679 GLsizei stride
, const GLvoid
*ptr
)
681 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
682 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
683 INT_BIT
| UNSIGNED_INT_BIT
);
684 const GLboolean normalized
= GL_FALSE
;
685 const GLboolean integer
= GL_TRUE
;
686 GET_CURRENT_CONTEXT(ctx
);
688 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
689 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
693 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
695 size
, type
, stride
, normalized
, integer
, ptr
);
701 _mesa_EnableVertexAttribArray(GLuint index
)
703 struct gl_vertex_array_object
*vao
;
704 GET_CURRENT_CONTEXT(ctx
);
706 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
707 _mesa_error(ctx
, GL_INVALID_VALUE
,
708 "glEnableVertexAttribArrayARB(index)");
712 vao
= ctx
->Array
.VAO
;
714 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(vao
->_VertexAttrib
));
716 if (!vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
717 /* was disabled, now being enabled */
718 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
719 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
720 vao
->_Enabled
|= VERT_BIT_GENERIC(index
);
721 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
727 _mesa_DisableVertexAttribArray(GLuint index
)
729 struct gl_vertex_array_object
*vao
;
730 GET_CURRENT_CONTEXT(ctx
);
732 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
733 _mesa_error(ctx
, GL_INVALID_VALUE
,
734 "glDisableVertexAttribArrayARB(index)");
738 vao
= ctx
->Array
.VAO
;
740 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(vao
->_VertexAttrib
));
742 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
743 /* was enabled, now being disabled */
744 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
745 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
746 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
747 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
753 * Return info for a vertex attribute array (no alias with legacy
754 * vertex attributes (pos, normal, color, etc)). This function does
755 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
758 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
761 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
762 const struct gl_vertex_attrib_array
*array
;
764 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
765 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
769 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(vao
->VertexAttrib
));
771 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
774 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
775 return array
->Enabled
;
776 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
777 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
778 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
779 return array
->Stride
;
780 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
782 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
783 return array
->Normalized
;
784 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
785 return vao
->VertexBinding
[array
->VertexBinding
].BufferObj
->Name
;
786 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
787 if ((_mesa_is_desktop_gl(ctx
)
788 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
789 || _mesa_is_gles3(ctx
)) {
790 return array
->Integer
;
793 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
794 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
795 || _mesa_is_gles3(ctx
)) {
796 return vao
->VertexBinding
[array
->VertexBinding
].InstanceDivisor
;
799 case GL_VERTEX_ATTRIB_BINDING
:
800 if (_mesa_is_desktop_gl(ctx
)) {
801 return array
->VertexBinding
- VERT_ATTRIB_GENERIC0
;
804 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
805 if (_mesa_is_desktop_gl(ctx
)) {
806 return array
->RelativeOffset
;
814 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
819 static const GLfloat
*
820 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
823 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
824 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
828 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
829 _mesa_error(ctx
, GL_INVALID_VALUE
,
830 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
834 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.VAO
->_VertexAttrib
));
836 FLUSH_CURRENT(ctx
, 0);
837 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
841 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
843 GET_CURRENT_CONTEXT(ctx
);
845 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
846 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
852 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
853 "glGetVertexAttribfv");
859 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
861 GET_CURRENT_CONTEXT(ctx
);
863 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
864 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
866 params
[0] = (GLdouble
) v
[0];
867 params
[1] = (GLdouble
) v
[1];
868 params
[2] = (GLdouble
) v
[2];
869 params
[3] = (GLdouble
) v
[3];
873 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
874 "glGetVertexAttribdv");
880 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
882 GET_CURRENT_CONTEXT(ctx
);
884 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
885 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
887 /* XXX should floats in[0,1] be scaled to full int range? */
888 params
[0] = (GLint
) v
[0];
889 params
[1] = (GLint
) v
[1];
890 params
[2] = (GLint
) v
[2];
891 params
[3] = (GLint
) v
[3];
895 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
896 "glGetVertexAttribiv");
903 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
905 GET_CURRENT_CONTEXT(ctx
);
907 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
908 const GLint
*v
= (const GLint
*)
909 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
915 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
916 "glGetVertexAttribIiv");
923 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
925 GET_CURRENT_CONTEXT(ctx
);
927 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
928 const GLuint
*v
= (const GLuint
*)
929 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
935 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
936 "glGetVertexAttribIuiv");
942 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
944 GET_CURRENT_CONTEXT(ctx
);
946 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
947 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
951 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
952 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
956 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.VAO
->_VertexAttrib
));
958 *pointer
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
963 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
964 GLsizei count
, const GLvoid
*ptr
)
967 _mesa_VertexPointer(size
, type
, stride
, ptr
);
972 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
976 _mesa_NormalPointer(type
, stride
, ptr
);
981 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
985 _mesa_ColorPointer(size
, type
, stride
, ptr
);
990 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
994 _mesa_IndexPointer(type
, stride
, ptr
);
999 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1000 GLsizei count
, const GLvoid
*ptr
)
1003 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1008 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1011 _mesa_EdgeFlagPointer(stride
, ptr
);
1016 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1018 GET_CURRENT_CONTEXT(ctx
);
1019 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1020 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1021 GLenum ctype
= 0; /* color type */
1022 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1023 const GLint toffset
= 0; /* always zero */
1024 GLint defstride
; /* default stride */
1027 FLUSH_VERTICES(ctx
, 0);
1029 f
= sizeof(GLfloat
);
1030 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1033 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1039 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1040 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1045 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1046 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1051 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1052 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1053 ctype
= GL_UNSIGNED_BYTE
;
1056 defstride
= c
+ 2*f
;
1059 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1060 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1061 ctype
= GL_UNSIGNED_BYTE
;
1064 defstride
= c
+ 3*f
;
1067 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1068 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1075 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1076 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1081 case GL_C4F_N3F_V3F
:
1082 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1083 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1091 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1092 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1097 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1098 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1102 case GL_T2F_C4UB_V3F
:
1103 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1104 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1105 ctype
= GL_UNSIGNED_BYTE
;
1110 case GL_T2F_C3F_V3F
:
1111 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1112 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1118 case GL_T2F_N3F_V3F
:
1119 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1120 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1125 case GL_T2F_C4F_N3F_V3F
:
1126 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1127 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1134 case GL_T4F_C4F_N3F_V4F
:
1135 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1136 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1144 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1152 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1153 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1154 /* XXX also disable secondary color and generic arrays? */
1158 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1159 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1160 (GLubyte
*) pointer
+ toffset
);
1163 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1168 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1169 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1170 (GLubyte
*) pointer
+ coffset
);
1173 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1179 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1180 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1183 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1187 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1188 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1189 (GLubyte
*) pointer
+ voffset
);
1194 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1196 GET_CURRENT_CONTEXT(ctx
);
1198 FLUSH_VERTICES(ctx
, 0);
1200 if (MESA_VERBOSE
& VERBOSE_API
)
1201 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1204 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1208 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1211 if (ctx
->Array
.LockCount
!= 0) {
1212 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1216 ctx
->Array
.LockFirst
= first
;
1217 ctx
->Array
.LockCount
= count
;
1219 ctx
->NewState
|= _NEW_ARRAY
;
1224 _mesa_UnlockArraysEXT( void )
1226 GET_CURRENT_CONTEXT(ctx
);
1228 FLUSH_VERTICES(ctx
, 0);
1230 if (MESA_VERBOSE
& VERBOSE_API
)
1231 _mesa_debug(ctx
, "glUnlockArrays\n");
1233 if (ctx
->Array
.LockCount
== 0) {
1234 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1238 ctx
->Array
.LockFirst
= 0;
1239 ctx
->Array
.LockCount
= 0;
1240 ctx
->NewState
|= _NEW_ARRAY
;
1244 /* GL_EXT_multi_draw_arrays */
1246 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1247 const GLsizei
*count
, GLsizei primcount
)
1249 GET_CURRENT_CONTEXT(ctx
);
1252 FLUSH_VERTICES(ctx
, 0);
1254 for (i
= 0; i
< primcount
; i
++) {
1256 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1262 /* GL_IBM_multimode_draw_arrays */
1264 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1265 const GLsizei
* count
,
1266 GLsizei primcount
, GLint modestride
)
1268 GET_CURRENT_CONTEXT(ctx
);
1271 FLUSH_VERTICES(ctx
, 0);
1273 for ( i
= 0 ; i
< primcount
; i
++ ) {
1274 if ( count
[i
] > 0 ) {
1275 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1276 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1282 /* GL_IBM_multimode_draw_arrays */
1284 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1285 GLenum type
, const GLvoid
* const * indices
,
1286 GLsizei primcount
, GLint modestride
)
1288 GET_CURRENT_CONTEXT(ctx
);
1291 FLUSH_VERTICES(ctx
, 0);
1293 /* XXX not sure about ARB_vertex_buffer_object handling here */
1295 for ( i
= 0 ; i
< primcount
; i
++ ) {
1296 if ( count
[i
] > 0 ) {
1297 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1298 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1306 * GL_NV_primitive_restart and GL 3.1
1309 _mesa_PrimitiveRestartIndex(GLuint index
)
1311 GET_CURRENT_CONTEXT(ctx
);
1313 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1314 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1318 if (ctx
->Array
.RestartIndex
!= index
) {
1319 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1320 ctx
->Array
.RestartIndex
= index
;
1326 * See GL_ARB_instanced_arrays.
1327 * Note that the instance divisor only applies to generic arrays, not
1328 * the legacy vertex arrays.
1331 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1333 GET_CURRENT_CONTEXT(ctx
);
1335 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1337 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1338 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1342 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1343 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1348 ASSERT(genericIndex
< Elements(ctx
->Array
.VAO
->VertexAttrib
));
1350 /* The ARB_vertex_attrib_binding spec says:
1354 * void VertexAttribDivisor(uint index, uint divisor);
1356 * is equivalent to (assuming no errors are generated):
1358 * VertexAttribBinding(index, index);
1359 * VertexBindingDivisor(index, divisor);"
1361 vertex_attrib_binding(ctx
, genericIndex
, genericIndex
);
1362 vertex_binding_divisor(ctx
, genericIndex
, divisor
);
1367 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1369 /* From the OpenGL 4.3 core specification, page 302:
1370 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1371 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1374 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1376 case GL_UNSIGNED_BYTE
:
1378 case GL_UNSIGNED_SHORT
:
1380 case GL_UNSIGNED_INT
:
1383 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1387 return ctx
->Array
.RestartIndex
;
1392 * GL_ARB_vertex_attrib_binding
1395 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1398 GET_CURRENT_CONTEXT(ctx
);
1399 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1400 struct gl_buffer_object
*vbo
;
1402 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1404 /* The ARB_vertex_attrib_binding spec says:
1406 * "An INVALID_OPERATION error is generated if no vertex array object
1409 if (ctx
->API
== API_OPENGL_CORE
&&
1410 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1411 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1412 "glBindVertexBuffer(No array object bound)");
1416 /* The ARB_vertex_attrib_binding spec says:
1418 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1419 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1421 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1422 _mesa_error(ctx
, GL_INVALID_VALUE
,
1423 "glBindVertexBuffer(bindingindex=%u > "
1424 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1429 /* The ARB_vertex_attrib_binding spec says:
1431 * "The error INVALID_VALUE is generated if <stride> or <offset>
1435 _mesa_error(ctx
, GL_INVALID_VALUE
,
1436 "glBindVertexBuffer(offset=%" PRId64
" < 0)",
1442 _mesa_error(ctx
, GL_INVALID_VALUE
,
1443 "glBindVertexBuffer(stride=%d < 0)", stride
);
1447 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1448 stride
> ctx
->Const
.MaxVertexAttribStride
) {
1449 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindVertexBuffer(stride=%d > "
1450 "GL_MAX_VERTEX_ATTRIB_STRIDE)", stride
);
1454 if (buffer
== vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1455 vbo
= vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1456 } else if (buffer
!= 0) {
1457 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1459 /* From the GL_ARB_vertex_attrib_array spec:
1461 * "[Core profile only:]
1462 * An INVALID_OPERATION error is generated if buffer is not zero or a
1463 * name returned from a previous call to GenBuffers, or if such a name
1464 * has since been deleted with DeleteBuffers.
1466 * Otherwise, we fall back to the same compat profile behavior as other
1467 * object references (automatically gen it).
1469 if (!_mesa_handle_bind_buffer_gen(ctx
, GL_ARRAY_BUFFER
, buffer
,
1470 &vbo
, "glBindVertexBuffer"))
1473 /* The ARB_vertex_attrib_binding spec says:
1475 * "If <buffer> is zero, any buffer object attached to this
1476 * bindpoint is detached."
1478 vbo
= ctx
->Shared
->NullBufferObj
;
1481 bind_vertex_buffer(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
),
1482 vbo
, offset
, stride
);
1487 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1488 const GLintptr
*offsets
, const GLsizei
*strides
)
1490 GET_CURRENT_CONTEXT(ctx
);
1491 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1494 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1496 /* The ARB_vertex_attrib_binding spec says:
1498 * "An INVALID_OPERATION error is generated if no
1499 * vertex array object is bound."
1501 if (ctx
->API
== API_OPENGL_CORE
&&
1502 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1503 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1504 "glBindVertexBuffers(No array object bound)");
1508 /* The ARB_multi_bind spec says:
1510 * "An INVALID_OPERATION error is generated if <first> + <count>
1511 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1513 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1514 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1515 "glBindVertexBuffers(first=%u + count=%d > the value of "
1516 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1517 first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1523 * The ARB_multi_bind spec says:
1525 * "If <buffers> is NULL, each affected vertex buffer binding point
1526 * from <first> through <first>+<count>-1 will be reset to have no
1527 * bound buffer object. In this case, the offsets and strides
1528 * associated with the binding points are set to default values,
1529 * ignoring <offsets> and <strides>."
1531 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1533 for (i
= 0; i
< count
; i
++)
1534 bind_vertex_buffer(ctx
, VERT_ATTRIB_GENERIC(first
+ i
), vbo
, 0, 16);
1539 /* Note that the error semantics for multi-bind commands differ from
1540 * those of other GL commands.
1542 * The Issues section in the ARB_multi_bind spec says:
1544 * "(11) Typically, OpenGL specifies that if an error is generated by
1545 * a command, that command has no effect. This is somewhat
1546 * unfortunate for multi-bind commands, because it would require
1547 * a first pass to scan the entire list of bound objects for
1548 * errors and then a second pass to actually perform the
1549 * bindings. Should we have different error semantics?
1551 * RESOLVED: Yes. In this specification, when the parameters for
1552 * one of the <count> binding points are invalid, that binding
1553 * point is not updated and an error will be generated. However,
1554 * other binding points in the same command will be updated if
1555 * their parameters are valid and no other error occurs."
1558 _mesa_begin_bufferobj_lookups(ctx
);
1560 for (i
= 0; i
< count
; i
++) {
1561 struct gl_buffer_object
*vbo
;
1563 /* The ARB_multi_bind spec says:
1565 * "An INVALID_VALUE error is generated if any value in
1566 * <offsets> or <strides> is negative (per binding)."
1568 if (offsets
[i
] < 0) {
1569 _mesa_error(ctx
, GL_INVALID_VALUE
,
1570 "glBindVertexBuffers(offsets[%u]=%" PRId64
" < 0)",
1571 i
, (int64_t) offsets
[i
]);
1575 if (strides
[i
] < 0) {
1576 _mesa_error(ctx
, GL_INVALID_VALUE
,
1577 "glBindVertexBuffers(strides[%u]=%d < 0)",
1582 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1583 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
1584 _mesa_error(ctx
, GL_INVALID_VALUE
,
1585 "glBindVertexBuffers(strides[%u]=%d > "
1586 "GL_MAX_VERTEX_ATTRIB_STRIDE)", i
, strides
[i
]);
1591 struct gl_vertex_buffer_binding
*binding
=
1592 &vao
->VertexBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1594 if (buffers
[i
] == binding
->BufferObj
->Name
)
1595 vbo
= binding
->BufferObj
;
1597 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
1598 "glBindVertexBuffers");
1603 vbo
= ctx
->Shared
->NullBufferObj
;
1606 bind_vertex_buffer(ctx
, VERT_ATTRIB_GENERIC(first
+ i
), vbo
,
1607 offsets
[i
], strides
[i
]);
1610 _mesa_end_bufferobj_lookups(ctx
);
1615 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1616 GLboolean normalized
, GLuint relativeOffset
)
1618 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1619 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1620 INT_BIT
| UNSIGNED_INT_BIT
|
1621 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1623 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1624 INT_2_10_10_10_REV_BIT
|
1625 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1627 GET_CURRENT_CONTEXT(ctx
);
1628 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1630 /* The ARB_vertex_attrib_binding spec says:
1632 * "An INVALID_OPERATION error is generated under any of the following
1634 * - if no vertex array object is currently bound (see section 2.10);
1637 if (ctx
->API
== API_OPENGL_CORE
&&
1638 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1639 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1640 "glVertexAttribFormat(No array object bound)");
1644 /* The ARB_vertex_attrib_binding spec says:
1646 * "The error INVALID_VALUE is generated if index is greater than or equal
1647 * to the value of MAX_VERTEX_ATTRIBS."
1649 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1650 _mesa_error(ctx
, GL_INVALID_VALUE
,
1651 "glVertexAttribFormat(attribindex=%u > "
1652 "GL_MAX_VERTEX_ATTRIBS)",
1657 FLUSH_VERTICES(ctx
, 0);
1659 update_array_format(ctx
, "glVertexAttribFormat",
1660 VERT_ATTRIB_GENERIC(attribIndex
),
1661 legalTypes
, 1, BGRA_OR_4
, size
, type
, normalized
,
1662 GL_FALSE
, relativeOffset
);
1667 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1668 GLuint relativeOffset
)
1670 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1671 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1672 INT_BIT
| UNSIGNED_INT_BIT
);
1674 GET_CURRENT_CONTEXT(ctx
);
1675 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1677 /* The ARB_vertex_attrib_binding spec says:
1679 * "An INVALID_OPERATION error is generated under any of the following
1681 * - if no vertex array object is currently bound (see section 2.10);
1684 if (ctx
->API
== API_OPENGL_CORE
&&
1685 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1686 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1687 "glVertexAttribIFormat(No array object bound)");
1691 /* The ARB_vertex_attrib_binding spec says:
1693 * "The error INVALID_VALUE is generated if index is greater than
1694 * or equal to the value of MAX_VERTEX_ATTRIBS."
1696 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1697 _mesa_error(ctx
, GL_INVALID_VALUE
,
1698 "glVertexAttribIFormat(attribindex=%u > "
1699 "GL_MAX_VERTEX_ATTRIBS)",
1704 FLUSH_VERTICES(ctx
, 0);
1706 update_array_format(ctx
, "glVertexAttribIFormat",
1707 VERT_ATTRIB_GENERIC(attribIndex
),
1708 legalTypes
, 1, 4, size
, type
, GL_FALSE
, GL_TRUE
,
1714 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1715 GLuint relativeOffset
)
1717 const GLbitfield legalTypes
= DOUBLE_BIT
;
1719 GET_CURRENT_CONTEXT(ctx
);
1720 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1722 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
1724 * "An INVALID_OPERATION error is generated under any of the following
1726 * • if no vertex array object is currently bound (see section 10.4);
1729 * This language is missing from the extension spec, but we assume
1730 * that this is an oversight.
1732 if (ctx
->API
== API_OPENGL_CORE
&&
1733 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1734 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1735 "glVertexAttribLFormat(No array object bound)");
1739 /* The ARB_vertex_attrib_binding spec says:
1741 * "The error INVALID_VALUE is generated if <attribindex> is greater than
1742 * or equal to the value of MAX_VERTEX_ATTRIBS."
1744 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1745 _mesa_error(ctx
, GL_INVALID_VALUE
,
1746 "glVertexAttribLFormat(attribindex=%u > "
1747 "GL_MAX_VERTEX_ATTRIBS)",
1752 FLUSH_VERTICES(ctx
, 0);
1754 update_array_format(ctx
, "glVertexAttribLFormat",
1755 VERT_ATTRIB_GENERIC(attribIndex
),
1756 legalTypes
, 1, 4, size
, type
, GL_FALSE
, GL_FALSE
,
1762 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
1764 GET_CURRENT_CONTEXT(ctx
);
1765 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1767 /* The ARB_vertex_attrib_binding spec says:
1769 * "An INVALID_OPERATION error is generated if no vertex array object
1772 if (ctx
->API
== API_OPENGL_CORE
&&
1773 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1774 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1775 "glVertexAttribBinding(No array object bound)");
1779 /* The ARB_vertex_attrib_binding spec says:
1781 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1782 * <bindingindex> must be less than the value of
1783 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1786 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1787 _mesa_error(ctx
, GL_INVALID_VALUE
,
1788 "glVertexAttribBinding(attribindex=%u >= "
1789 "GL_MAX_VERTEX_ATTRIBS)",
1794 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1795 _mesa_error(ctx
, GL_INVALID_VALUE
,
1796 "glVertexAttribBinding(bindingindex=%u >= "
1797 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1802 ASSERT(VERT_ATTRIB_GENERIC(attribIndex
) <
1803 Elements(ctx
->Array
.VAO
->VertexAttrib
));
1805 vertex_attrib_binding(ctx
, VERT_ATTRIB_GENERIC(attribIndex
),
1806 VERT_ATTRIB_GENERIC(bindingIndex
));
1811 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
1813 GET_CURRENT_CONTEXT(ctx
);
1814 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1816 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1817 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexBindingDivisor()");
1821 /* The ARB_vertex_attrib_binding spec says:
1823 * "An INVALID_OPERATION error is generated if no vertex array object
1826 if (ctx
->API
== API_OPENGL_CORE
&&
1827 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1828 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1829 "glVertexBindingDivisor(No array object bound)");
1833 /* The ARB_vertex_attrib_binding spec says:
1835 * "An INVALID_VALUE error is generated if <bindingindex> is greater
1836 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
1838 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1839 _mesa_error(ctx
, GL_INVALID_VALUE
,
1840 "glVertexBindingDivisor(bindingindex=%u > "
1841 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1846 vertex_binding_divisor(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
1851 * Copy one client vertex array to another.
1854 _mesa_copy_client_array(struct gl_context
*ctx
,
1855 struct gl_client_array
*dst
,
1856 struct gl_client_array
*src
)
1858 dst
->Size
= src
->Size
;
1859 dst
->Type
= src
->Type
;
1860 dst
->Format
= src
->Format
;
1861 dst
->Stride
= src
->Stride
;
1862 dst
->StrideB
= src
->StrideB
;
1863 dst
->Ptr
= src
->Ptr
;
1864 dst
->Enabled
= src
->Enabled
;
1865 dst
->Normalized
= src
->Normalized
;
1866 dst
->Integer
= src
->Integer
;
1867 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1868 dst
->_ElementSize
= src
->_ElementSize
;
1869 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1873 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
1874 struct gl_vertex_attrib_array
*dst
,
1875 const struct gl_vertex_attrib_array
*src
)
1877 dst
->Size
= src
->Size
;
1878 dst
->Type
= src
->Type
;
1879 dst
->Format
= src
->Format
;
1880 dst
->VertexBinding
= src
->VertexBinding
;
1881 dst
->RelativeOffset
= src
->RelativeOffset
;
1882 dst
->Format
= src
->Format
;
1883 dst
->Integer
= src
->Integer
;
1884 dst
->Normalized
= src
->Normalized
;
1885 dst
->Ptr
= src
->Ptr
;
1886 dst
->Enabled
= src
->Enabled
;
1887 dst
->_ElementSize
= src
->_ElementSize
;
1891 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
1892 struct gl_vertex_buffer_binding
*dst
,
1893 const struct gl_vertex_buffer_binding
*src
)
1895 dst
->Offset
= src
->Offset
;
1896 dst
->Stride
= src
->Stride
;
1897 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1898 dst
->_BoundArrays
= src
->_BoundArrays
;
1900 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1904 * Print vertex array's fields.
1907 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1910 printf(" %s[%d]: ", name
, index
);
1912 printf(" %s: ", name
);
1913 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
1914 array
->Ptr
, array
->Type
, array
->Size
,
1915 array
->_ElementSize
, array
->StrideB
,
1916 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
);
1921 * Print current vertex object/array info. For debug.
1924 _mesa_print_arrays(struct gl_context
*ctx
)
1926 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1929 printf("Array Object %u\n", vao
->Name
);
1930 if (vao
->_VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
1931 print_array("Vertex", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_POS
]);
1932 if (vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
1933 print_array("Normal", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
]);
1934 if (vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
1935 print_array("Color", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
]);
1936 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
1937 if (vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
1938 print_array("TexCoord", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
1939 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
1940 if (vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
1941 print_array("Attrib", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
1946 * Initialize vertex array state for given context.
1949 _mesa_init_varray(struct gl_context
*ctx
)
1951 ctx
->Array
.DefaultVAO
= ctx
->Driver
.NewArrayObject(ctx
, 0);
1952 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
1953 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1955 ctx
->Array
.Objects
= _mesa_NewHashTable();
1960 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1963 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1965 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
1966 struct gl_context
*ctx
= (struct gl_context
*) userData
;
1967 _mesa_delete_vao(ctx
, vao
);
1972 * Free vertex array state for given context.
1975 _mesa_free_varray_data(struct gl_context
*ctx
)
1977 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1978 _mesa_DeleteHashTable(ctx
->Array
.Objects
);