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 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
429 * "An INVALID_OPERATION error is generated under any of the following
434 * * any of the *Pointer commands specifying the location and
435 * organization of vertex array data are called while zero is bound
436 * to the ARRAY_BUFFER buffer object binding point (see section
437 * 2.9.6), and the pointer argument is not NULL."
439 if (ptr
!= NULL
&& ctx
->Array
.VAO
->ARBsemantics
&&
440 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
441 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
445 if (!update_array_format(ctx
, func
, attrib
, legalTypesMask
, sizeMin
,
446 sizeMax
, size
, type
, normalized
, integer
, 0)) {
450 /* Reset the vertex attrib binding */
451 vertex_attrib_binding(ctx
, attrib
, attrib
);
453 /* The Stride and Ptr fields are not set by update_array_format() */
454 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
455 array
->Stride
= stride
;
456 array
->Ptr
= (const GLvoid
*) ptr
;
458 /* Update the vertex buffer binding */
459 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
460 bind_vertex_buffer(ctx
, attrib
, ctx
->Array
.ArrayBufferObj
,
461 (GLintptr
) ptr
, effectiveStride
);
466 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
468 GET_CURRENT_CONTEXT(ctx
);
469 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
470 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
471 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
472 DOUBLE_BIT
| HALF_BIT
|
473 UNSIGNED_INT_2_10_10_10_REV_BIT
|
474 INT_2_10_10_10_REV_BIT
);
476 FLUSH_VERTICES(ctx
, 0);
478 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
480 size
, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
485 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
487 GET_CURRENT_CONTEXT(ctx
);
488 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
489 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
490 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
491 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
492 UNSIGNED_INT_2_10_10_10_REV_BIT
|
493 INT_2_10_10_10_REV_BIT
);
495 FLUSH_VERTICES(ctx
, 0);
497 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
499 3, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
504 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
506 GET_CURRENT_CONTEXT(ctx
);
507 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
508 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
509 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
510 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
511 INT_BIT
| UNSIGNED_INT_BIT
|
512 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
513 UNSIGNED_INT_2_10_10_10_REV_BIT
|
514 INT_2_10_10_10_REV_BIT
);
515 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
517 FLUSH_VERTICES(ctx
, 0);
519 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
520 legalTypes
, sizeMin
, BGRA_OR_4
,
521 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
526 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
528 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
529 GET_CURRENT_CONTEXT(ctx
);
531 FLUSH_VERTICES(ctx
, 0);
533 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
535 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
540 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
542 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
543 FLOAT_BIT
| DOUBLE_BIT
);
544 GET_CURRENT_CONTEXT(ctx
);
546 FLUSH_VERTICES(ctx
, 0);
548 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
550 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
555 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
556 GLsizei stride
, const GLvoid
*ptr
)
558 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
559 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
560 INT_BIT
| UNSIGNED_INT_BIT
|
561 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
562 UNSIGNED_INT_2_10_10_10_REV_BIT
|
563 INT_2_10_10_10_REV_BIT
);
564 GET_CURRENT_CONTEXT(ctx
);
566 FLUSH_VERTICES(ctx
, 0);
568 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
569 legalTypes
, 3, BGRA_OR_4
,
570 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
575 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
578 GET_CURRENT_CONTEXT(ctx
);
579 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
580 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
581 : (SHORT_BIT
| INT_BIT
|
582 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
583 UNSIGNED_INT_2_10_10_10_REV_BIT
|
584 INT_2_10_10_10_REV_BIT
);
585 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
586 const GLuint unit
= ctx
->Array
.ActiveTexture
;
588 FLUSH_VERTICES(ctx
, 0);
590 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
591 legalTypes
, sizeMin
, 4,
592 size
, type
, stride
, GL_FALSE
, GL_FALSE
,
598 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
600 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
601 /* this is the same type that glEdgeFlag uses */
602 const GLboolean integer
= GL_FALSE
;
603 GET_CURRENT_CONTEXT(ctx
);
605 FLUSH_VERTICES(ctx
, 0);
607 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
609 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, ptr
);
614 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
616 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
617 GET_CURRENT_CONTEXT(ctx
);
619 FLUSH_VERTICES(ctx
, 0);
621 if (ctx
->API
!= API_OPENGLES
) {
622 _mesa_error(ctx
, GL_INVALID_OPERATION
,
623 "glPointSizePointer(ES 1.x only)");
627 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
629 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
634 * Set a generic vertex attribute array.
635 * Note that these arrays DO NOT alias the conventional GL vertex arrays
636 * (position, normal, color, fog, texcoord, etc).
639 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
640 GLboolean normalized
,
641 GLsizei stride
, const GLvoid
*ptr
)
643 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
644 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
645 INT_BIT
| UNSIGNED_INT_BIT
|
646 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
647 FIXED_ES_BIT
| FIXED_GL_BIT
|
648 UNSIGNED_INT_2_10_10_10_REV_BIT
|
649 INT_2_10_10_10_REV_BIT
|
650 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
651 GET_CURRENT_CONTEXT(ctx
);
653 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
654 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
658 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
659 legalTypes
, 1, BGRA_OR_4
,
660 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
665 * GL_EXT_gpu_shader4 / GL 3.0.
666 * Set an integer-valued vertex attribute array.
667 * Note that these arrays DO NOT alias the conventional GL vertex arrays
668 * (position, normal, color, fog, texcoord, etc).
671 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
672 GLsizei stride
, const GLvoid
*ptr
)
674 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
675 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
676 INT_BIT
| UNSIGNED_INT_BIT
);
677 const GLboolean normalized
= GL_FALSE
;
678 const GLboolean integer
= GL_TRUE
;
679 GET_CURRENT_CONTEXT(ctx
);
681 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
682 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
686 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
688 size
, type
, stride
, normalized
, integer
, ptr
);
694 _mesa_EnableVertexAttribArray(GLuint index
)
696 struct gl_vertex_array_object
*vao
;
697 GET_CURRENT_CONTEXT(ctx
);
699 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
700 _mesa_error(ctx
, GL_INVALID_VALUE
,
701 "glEnableVertexAttribArrayARB(index)");
705 vao
= ctx
->Array
.VAO
;
707 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(vao
->_VertexAttrib
));
709 if (!vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
710 /* was disabled, now being enabled */
711 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
712 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
713 vao
->_Enabled
|= VERT_BIT_GENERIC(index
);
714 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
720 _mesa_DisableVertexAttribArray(GLuint index
)
722 struct gl_vertex_array_object
*vao
;
723 GET_CURRENT_CONTEXT(ctx
);
725 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
726 _mesa_error(ctx
, GL_INVALID_VALUE
,
727 "glDisableVertexAttribArrayARB(index)");
731 vao
= ctx
->Array
.VAO
;
733 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(vao
->_VertexAttrib
));
735 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
736 /* was enabled, now being disabled */
737 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
738 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
739 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
740 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
746 * Return info for a vertex attribute array (no alias with legacy
747 * vertex attributes (pos, normal, color, etc)). This function does
748 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
751 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
754 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
755 const struct gl_vertex_attrib_array
*array
;
757 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
758 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
762 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(vao
->VertexAttrib
));
764 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
767 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
768 return array
->Enabled
;
769 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
770 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
771 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
772 return array
->Stride
;
773 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
775 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
776 return array
->Normalized
;
777 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
778 return vao
->VertexBinding
[array
->VertexBinding
].BufferObj
->Name
;
779 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
780 if ((_mesa_is_desktop_gl(ctx
)
781 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
782 || _mesa_is_gles3(ctx
)) {
783 return array
->Integer
;
786 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
787 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
788 || _mesa_is_gles3(ctx
)) {
789 return vao
->VertexBinding
[array
->VertexBinding
].InstanceDivisor
;
792 case GL_VERTEX_ATTRIB_BINDING
:
793 if (_mesa_is_desktop_gl(ctx
)) {
794 return array
->VertexBinding
- VERT_ATTRIB_GENERIC0
;
797 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
798 if (_mesa_is_desktop_gl(ctx
)) {
799 return array
->RelativeOffset
;
807 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
812 static const GLfloat
*
813 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
816 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
817 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
821 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
822 _mesa_error(ctx
, GL_INVALID_VALUE
,
823 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
827 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.VAO
->_VertexAttrib
));
829 FLUSH_CURRENT(ctx
, 0);
830 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
834 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
836 GET_CURRENT_CONTEXT(ctx
);
838 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
839 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
845 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
846 "glGetVertexAttribfv");
852 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
854 GET_CURRENT_CONTEXT(ctx
);
856 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
857 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
859 params
[0] = (GLdouble
) v
[0];
860 params
[1] = (GLdouble
) v
[1];
861 params
[2] = (GLdouble
) v
[2];
862 params
[3] = (GLdouble
) v
[3];
866 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
867 "glGetVertexAttribdv");
873 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
875 GET_CURRENT_CONTEXT(ctx
);
877 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
878 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
880 /* XXX should floats in[0,1] be scaled to full int range? */
881 params
[0] = (GLint
) v
[0];
882 params
[1] = (GLint
) v
[1];
883 params
[2] = (GLint
) v
[2];
884 params
[3] = (GLint
) v
[3];
888 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
889 "glGetVertexAttribiv");
896 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
898 GET_CURRENT_CONTEXT(ctx
);
900 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
901 const GLint
*v
= (const GLint
*)
902 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
908 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
909 "glGetVertexAttribIiv");
916 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
918 GET_CURRENT_CONTEXT(ctx
);
920 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
921 const GLuint
*v
= (const GLuint
*)
922 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
928 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
929 "glGetVertexAttribIuiv");
935 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
937 GET_CURRENT_CONTEXT(ctx
);
939 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
940 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
944 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
945 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
949 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.VAO
->_VertexAttrib
));
951 *pointer
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
956 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
957 GLsizei count
, const GLvoid
*ptr
)
960 _mesa_VertexPointer(size
, type
, stride
, ptr
);
965 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
969 _mesa_NormalPointer(type
, stride
, ptr
);
974 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
978 _mesa_ColorPointer(size
, type
, stride
, ptr
);
983 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
987 _mesa_IndexPointer(type
, stride
, ptr
);
992 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
993 GLsizei count
, const GLvoid
*ptr
)
996 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1001 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1004 _mesa_EdgeFlagPointer(stride
, ptr
);
1009 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1011 GET_CURRENT_CONTEXT(ctx
);
1012 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1013 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1014 GLenum ctype
= 0; /* color type */
1015 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1016 const GLint toffset
= 0; /* always zero */
1017 GLint defstride
; /* default stride */
1020 FLUSH_VERTICES(ctx
, 0);
1022 f
= sizeof(GLfloat
);
1023 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1026 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1032 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1033 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1038 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1039 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1044 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1045 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1046 ctype
= GL_UNSIGNED_BYTE
;
1049 defstride
= c
+ 2*f
;
1052 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1053 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1054 ctype
= GL_UNSIGNED_BYTE
;
1057 defstride
= c
+ 3*f
;
1060 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1061 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1068 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1069 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1074 case GL_C4F_N3F_V3F
:
1075 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1076 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1084 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1085 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1090 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1091 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1095 case GL_T2F_C4UB_V3F
:
1096 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1097 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1098 ctype
= GL_UNSIGNED_BYTE
;
1103 case GL_T2F_C3F_V3F
:
1104 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1105 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1111 case GL_T2F_N3F_V3F
:
1112 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1113 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1118 case GL_T2F_C4F_N3F_V3F
:
1119 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1120 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1127 case GL_T4F_C4F_N3F_V4F
:
1128 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1129 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1137 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1145 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1146 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1147 /* XXX also disable secondary color and generic arrays? */
1151 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1152 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1153 (GLubyte
*) pointer
+ toffset
);
1156 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1161 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1162 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1163 (GLubyte
*) pointer
+ coffset
);
1166 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1172 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1173 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1176 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1180 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1181 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1182 (GLubyte
*) pointer
+ voffset
);
1187 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1189 GET_CURRENT_CONTEXT(ctx
);
1191 FLUSH_VERTICES(ctx
, 0);
1193 if (MESA_VERBOSE
& VERBOSE_API
)
1194 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1197 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1201 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1204 if (ctx
->Array
.LockCount
!= 0) {
1205 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1209 ctx
->Array
.LockFirst
= first
;
1210 ctx
->Array
.LockCount
= count
;
1212 ctx
->NewState
|= _NEW_ARRAY
;
1217 _mesa_UnlockArraysEXT( void )
1219 GET_CURRENT_CONTEXT(ctx
);
1221 FLUSH_VERTICES(ctx
, 0);
1223 if (MESA_VERBOSE
& VERBOSE_API
)
1224 _mesa_debug(ctx
, "glUnlockArrays\n");
1226 if (ctx
->Array
.LockCount
== 0) {
1227 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1231 ctx
->Array
.LockFirst
= 0;
1232 ctx
->Array
.LockCount
= 0;
1233 ctx
->NewState
|= _NEW_ARRAY
;
1237 /* GL_EXT_multi_draw_arrays */
1239 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1240 const GLsizei
*count
, GLsizei primcount
)
1242 GET_CURRENT_CONTEXT(ctx
);
1245 FLUSH_VERTICES(ctx
, 0);
1247 for (i
= 0; i
< primcount
; i
++) {
1249 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1255 /* GL_IBM_multimode_draw_arrays */
1257 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1258 const GLsizei
* count
,
1259 GLsizei primcount
, GLint modestride
)
1261 GET_CURRENT_CONTEXT(ctx
);
1264 FLUSH_VERTICES(ctx
, 0);
1266 for ( i
= 0 ; i
< primcount
; i
++ ) {
1267 if ( count
[i
] > 0 ) {
1268 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1269 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1275 /* GL_IBM_multimode_draw_arrays */
1277 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1278 GLenum type
, const GLvoid
* const * indices
,
1279 GLsizei primcount
, GLint modestride
)
1281 GET_CURRENT_CONTEXT(ctx
);
1284 FLUSH_VERTICES(ctx
, 0);
1286 /* XXX not sure about ARB_vertex_buffer_object handling here */
1288 for ( i
= 0 ; i
< primcount
; i
++ ) {
1289 if ( count
[i
] > 0 ) {
1290 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1291 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1299 * GL_NV_primitive_restart and GL 3.1
1302 _mesa_PrimitiveRestartIndex(GLuint index
)
1304 GET_CURRENT_CONTEXT(ctx
);
1306 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1307 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1311 if (ctx
->Array
.RestartIndex
!= index
) {
1312 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1313 ctx
->Array
.RestartIndex
= index
;
1319 * See GL_ARB_instanced_arrays.
1320 * Note that the instance divisor only applies to generic arrays, not
1321 * the legacy vertex arrays.
1324 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1326 GET_CURRENT_CONTEXT(ctx
);
1328 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1330 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1331 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1335 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1336 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1341 ASSERT(genericIndex
< Elements(ctx
->Array
.VAO
->VertexAttrib
));
1343 /* The ARB_vertex_attrib_binding spec says:
1347 * void VertexAttribDivisor(uint index, uint divisor);
1349 * is equivalent to (assuming no errors are generated):
1351 * VertexAttribBinding(index, index);
1352 * VertexBindingDivisor(index, divisor);"
1354 vertex_attrib_binding(ctx
, genericIndex
, genericIndex
);
1355 vertex_binding_divisor(ctx
, genericIndex
, divisor
);
1360 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1362 /* From the OpenGL 4.3 core specification, page 302:
1363 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1364 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1367 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1369 case GL_UNSIGNED_BYTE
:
1371 case GL_UNSIGNED_SHORT
:
1373 case GL_UNSIGNED_INT
:
1376 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1380 return ctx
->Array
.RestartIndex
;
1385 * GL_ARB_vertex_attrib_binding
1388 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1391 GET_CURRENT_CONTEXT(ctx
);
1392 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1393 struct gl_buffer_object
*vbo
;
1395 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1397 /* The ARB_vertex_attrib_binding spec says:
1399 * "An INVALID_OPERATION error is generated if no vertex array object
1402 if (ctx
->API
== API_OPENGL_CORE
&&
1403 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1404 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1405 "glBindVertexBuffer(No array object bound)");
1409 /* The ARB_vertex_attrib_binding spec says:
1411 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1412 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1414 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1415 _mesa_error(ctx
, GL_INVALID_VALUE
,
1416 "glBindVertexBuffer(bindingindex=%u > "
1417 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1422 /* The ARB_vertex_attrib_binding spec says:
1424 * "The error INVALID_VALUE is generated if <stride> or <offset>
1428 _mesa_error(ctx
, GL_INVALID_VALUE
,
1429 "glBindVertexBuffer(offset=%" PRId64
" < 0)",
1435 _mesa_error(ctx
, GL_INVALID_VALUE
,
1436 "glBindVertexBuffer(stride=%d < 0)", stride
);
1440 if (buffer
== vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1441 vbo
= vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1442 } else if (buffer
!= 0) {
1443 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1445 /* From the GL_ARB_vertex_attrib_array spec:
1447 * "[Core profile only:]
1448 * An INVALID_OPERATION error is generated if buffer is not zero or a
1449 * name returned from a previous call to GenBuffers, or if such a name
1450 * has since been deleted with DeleteBuffers.
1452 * Otherwise, we fall back to the same compat profile behavior as other
1453 * object references (automatically gen it).
1455 if (!_mesa_handle_bind_buffer_gen(ctx
, GL_ARRAY_BUFFER
, buffer
,
1456 &vbo
, "glBindVertexBuffer"))
1459 /* The ARB_vertex_attrib_binding spec says:
1461 * "If <buffer> is zero, any buffer object attached to this
1462 * bindpoint is detached."
1464 vbo
= ctx
->Shared
->NullBufferObj
;
1467 bind_vertex_buffer(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
),
1468 vbo
, offset
, stride
);
1473 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1474 const GLintptr
*offsets
, const GLsizei
*strides
)
1476 GET_CURRENT_CONTEXT(ctx
);
1477 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1480 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1482 /* The ARB_vertex_attrib_binding spec says:
1484 * "An INVALID_OPERATION error is generated if no
1485 * vertex array object is bound."
1487 if (ctx
->API
== API_OPENGL_CORE
&&
1488 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1489 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1490 "glBindVertexBuffers(No array object bound)");
1494 /* The ARB_multi_bind spec says:
1496 * "An INVALID_OPERATION error is generated if <first> + <count>
1497 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1499 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1500 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1501 "glBindVertexBuffers(first=%u + count=%d > the value of "
1502 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1503 first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1509 * The ARB_multi_bind spec says:
1511 * "If <buffers> is NULL, each affected vertex buffer binding point
1512 * from <first> through <first>+<count>-1 will be reset to have no
1513 * bound buffer object. In this case, the offsets and strides
1514 * associated with the binding points are set to default values,
1515 * ignoring <offsets> and <strides>."
1517 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1519 for (i
= 0; i
< count
; i
++)
1520 bind_vertex_buffer(ctx
, VERT_ATTRIB_GENERIC(first
+ i
), vbo
, 0, 16);
1525 /* Note that the error semantics for multi-bind commands differ from
1526 * those of other GL commands.
1528 * The Issues section in the ARB_multi_bind spec says:
1530 * "(11) Typically, OpenGL specifies that if an error is generated by
1531 * a command, that command has no effect. This is somewhat
1532 * unfortunate for multi-bind commands, because it would require
1533 * a first pass to scan the entire list of bound objects for
1534 * errors and then a second pass to actually perform the
1535 * bindings. Should we have different error semantics?
1537 * RESOLVED: Yes. In this specification, when the parameters for
1538 * one of the <count> binding points are invalid, that binding
1539 * point is not updated and an error will be generated. However,
1540 * other binding points in the same command will be updated if
1541 * their parameters are valid and no other error occurs."
1544 _mesa_begin_bufferobj_lookups(ctx
);
1546 for (i
= 0; i
< count
; i
++) {
1547 struct gl_buffer_object
*vbo
;
1549 /* The ARB_multi_bind spec says:
1551 * "An INVALID_VALUE error is generated if any value in
1552 * <offsets> or <strides> is negative (per binding)."
1554 if (offsets
[i
] < 0) {
1555 _mesa_error(ctx
, GL_INVALID_VALUE
,
1556 "glBindVertexBuffer(offsets[%u]=%" PRId64
" < 0)",
1557 i
, (int64_t) offsets
[i
]);
1561 if (strides
[i
] < 0) {
1562 _mesa_error(ctx
, GL_INVALID_VALUE
,
1563 "glBindVertexBuffer(strides[%u]=%d < 0)",
1569 struct gl_vertex_buffer_binding
*binding
=
1570 &vao
->VertexBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1572 if (buffers
[i
] == binding
->BufferObj
->Name
)
1573 vbo
= binding
->BufferObj
;
1575 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
1576 "glBindVertexBuffers");
1581 vbo
= ctx
->Shared
->NullBufferObj
;
1584 bind_vertex_buffer(ctx
, VERT_ATTRIB_GENERIC(first
+ i
), vbo
,
1585 offsets
[i
], strides
[i
]);
1588 _mesa_end_bufferobj_lookups(ctx
);
1593 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1594 GLboolean normalized
, GLuint relativeOffset
)
1596 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1597 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1598 INT_BIT
| UNSIGNED_INT_BIT
|
1599 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1601 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1602 INT_2_10_10_10_REV_BIT
|
1603 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1605 GET_CURRENT_CONTEXT(ctx
);
1606 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1608 /* The ARB_vertex_attrib_binding spec says:
1610 * "An INVALID_OPERATION error is generated under any of the following
1612 * - if no vertex array object is currently bound (see section 2.10);
1615 if (ctx
->API
== API_OPENGL_CORE
&&
1616 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1617 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1618 "glVertexAttribFormat(No array object bound)");
1622 /* The ARB_vertex_attrib_binding spec says:
1624 * "The error INVALID_VALUE is generated if index is greater than or equal
1625 * to the value of MAX_VERTEX_ATTRIBS."
1627 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1628 _mesa_error(ctx
, GL_INVALID_VALUE
,
1629 "glVertexAttribFormat(attribindex=%u > "
1630 "GL_MAX_VERTEX_ATTRIBS)",
1635 FLUSH_VERTICES(ctx
, 0);
1637 update_array_format(ctx
, "glVertexAttribFormat",
1638 VERT_ATTRIB_GENERIC(attribIndex
),
1639 legalTypes
, 1, BGRA_OR_4
, size
, type
, normalized
,
1640 GL_FALSE
, relativeOffset
);
1645 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1646 GLuint relativeOffset
)
1648 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1649 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1650 INT_BIT
| UNSIGNED_INT_BIT
);
1652 GET_CURRENT_CONTEXT(ctx
);
1653 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1655 /* The ARB_vertex_attrib_binding spec says:
1657 * "An INVALID_OPERATION error is generated under any of the following
1659 * - if no vertex array object is currently bound (see section 2.10);
1662 if (ctx
->API
== API_OPENGL_CORE
&&
1663 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1664 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1665 "glVertexAttribIFormat(No array object bound)");
1669 /* The ARB_vertex_attrib_binding spec says:
1671 * "The error INVALID_VALUE is generated if index is greater than
1672 * or equal to the value of MAX_VERTEX_ATTRIBS."
1674 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1675 _mesa_error(ctx
, GL_INVALID_VALUE
,
1676 "glVertexAttribIFormat(attribindex=%u > "
1677 "GL_MAX_VERTEX_ATTRIBS)",
1682 FLUSH_VERTICES(ctx
, 0);
1684 update_array_format(ctx
, "glVertexAttribIFormat",
1685 VERT_ATTRIB_GENERIC(attribIndex
),
1686 legalTypes
, 1, 4, size
, type
, GL_FALSE
, GL_TRUE
,
1692 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1693 GLuint relativeOffset
)
1695 const GLbitfield legalTypes
= DOUBLE_BIT
;
1697 GET_CURRENT_CONTEXT(ctx
);
1698 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1700 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
1702 * "An INVALID_OPERATION error is generated under any of the following
1704 * • if no vertex array object is currently bound (see section 10.4);
1707 * This language is missing from the extension spec, but we assume
1708 * that this is an oversight.
1710 if (ctx
->API
== API_OPENGL_CORE
&&
1711 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1712 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1713 "glVertexAttribLFormat(No array object bound)");
1717 /* The ARB_vertex_attrib_binding spec says:
1719 * "The error INVALID_VALUE is generated if <attribindex> is greater than
1720 * or equal to the value of MAX_VERTEX_ATTRIBS."
1722 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1723 _mesa_error(ctx
, GL_INVALID_VALUE
,
1724 "glVertexAttribLFormat(attribindex=%u > "
1725 "GL_MAX_VERTEX_ATTRIBS)",
1730 FLUSH_VERTICES(ctx
, 0);
1732 update_array_format(ctx
, "glVertexAttribLFormat",
1733 VERT_ATTRIB_GENERIC(attribIndex
),
1734 legalTypes
, 1, 4, size
, type
, GL_FALSE
, GL_FALSE
,
1740 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
1742 GET_CURRENT_CONTEXT(ctx
);
1743 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1745 /* The ARB_vertex_attrib_binding spec says:
1747 * "An INVALID_OPERATION error is generated if no vertex array object
1750 if (ctx
->API
== API_OPENGL_CORE
&&
1751 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1752 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1753 "glVertexAttribBinding(No array object bound)");
1757 /* The ARB_vertex_attrib_binding spec says:
1759 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1760 * <bindingindex> must be less than the value of
1761 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1764 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1765 _mesa_error(ctx
, GL_INVALID_VALUE
,
1766 "glVertexAttribBinding(attribindex=%u >= "
1767 "GL_MAX_VERTEX_ATTRIBS)",
1772 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1773 _mesa_error(ctx
, GL_INVALID_VALUE
,
1774 "glVertexAttribBinding(bindingindex=%u >= "
1775 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1780 ASSERT(VERT_ATTRIB_GENERIC(attribIndex
) <
1781 Elements(ctx
->Array
.VAO
->VertexAttrib
));
1783 vertex_attrib_binding(ctx
, VERT_ATTRIB_GENERIC(attribIndex
),
1784 VERT_ATTRIB_GENERIC(bindingIndex
));
1789 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
1791 GET_CURRENT_CONTEXT(ctx
);
1792 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1794 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1795 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexBindingDivisor()");
1799 /* The ARB_vertex_attrib_binding spec says:
1801 * "An INVALID_OPERATION error is generated if no vertex array object
1804 if (ctx
->API
== API_OPENGL_CORE
&&
1805 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1806 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1807 "glVertexBindingDivisor(No array object bound)");
1811 /* The ARB_vertex_attrib_binding spec says:
1813 * "An INVALID_VALUE error is generated if <bindingindex> is greater
1814 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
1816 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1817 _mesa_error(ctx
, GL_INVALID_VALUE
,
1818 "glVertexBindingDivisor(bindingindex=%u > "
1819 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1824 vertex_binding_divisor(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
1829 * Copy one client vertex array to another.
1832 _mesa_copy_client_array(struct gl_context
*ctx
,
1833 struct gl_client_array
*dst
,
1834 struct gl_client_array
*src
)
1836 dst
->Size
= src
->Size
;
1837 dst
->Type
= src
->Type
;
1838 dst
->Format
= src
->Format
;
1839 dst
->Stride
= src
->Stride
;
1840 dst
->StrideB
= src
->StrideB
;
1841 dst
->Ptr
= src
->Ptr
;
1842 dst
->Enabled
= src
->Enabled
;
1843 dst
->Normalized
= src
->Normalized
;
1844 dst
->Integer
= src
->Integer
;
1845 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1846 dst
->_ElementSize
= src
->_ElementSize
;
1847 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1848 dst
->_MaxElement
= src
->_MaxElement
;
1852 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
1853 struct gl_vertex_attrib_array
*dst
,
1854 const struct gl_vertex_attrib_array
*src
)
1856 dst
->Size
= src
->Size
;
1857 dst
->Type
= src
->Type
;
1858 dst
->Format
= src
->Format
;
1859 dst
->VertexBinding
= src
->VertexBinding
;
1860 dst
->RelativeOffset
= src
->RelativeOffset
;
1861 dst
->Format
= src
->Format
;
1862 dst
->Integer
= src
->Integer
;
1863 dst
->Normalized
= src
->Normalized
;
1864 dst
->Ptr
= src
->Ptr
;
1865 dst
->Enabled
= src
->Enabled
;
1866 dst
->_ElementSize
= src
->_ElementSize
;
1870 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
1871 struct gl_vertex_buffer_binding
*dst
,
1872 const struct gl_vertex_buffer_binding
*src
)
1874 dst
->Offset
= src
->Offset
;
1875 dst
->Stride
= src
->Stride
;
1876 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1877 dst
->_BoundArrays
= src
->_BoundArrays
;
1879 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1883 * Print vertex array's fields.
1886 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1889 printf(" %s[%d]: ", name
, index
);
1891 printf(" %s: ", name
);
1892 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
1893 array
->Ptr
, array
->Type
, array
->Size
,
1894 array
->_ElementSize
, array
->StrideB
,
1895 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
,
1896 array
->_MaxElement
);
1901 * Print current vertex object/array info. For debug.
1904 _mesa_print_arrays(struct gl_context
*ctx
)
1906 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1909 _mesa_update_vao_max_element(ctx
, vao
);
1911 printf("Array Object %u\n", vao
->Name
);
1912 if (vao
->_VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
1913 print_array("Vertex", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_POS
]);
1914 if (vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
1915 print_array("Normal", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
]);
1916 if (vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
1917 print_array("Color", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
]);
1918 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
1919 if (vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
1920 print_array("TexCoord", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
1921 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
1922 if (vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
1923 print_array("Attrib", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
1924 printf(" _MaxElement = %u\n", vao
->_MaxElement
);
1929 * Initialize vertex array state for given context.
1932 _mesa_init_varray(struct gl_context
*ctx
)
1934 ctx
->Array
.DefaultVAO
= ctx
->Driver
.NewArrayObject(ctx
, 0);
1935 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
1936 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1938 ctx
->Array
.Objects
= _mesa_NewHashTable();
1943 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1946 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1948 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
1949 struct gl_context
*ctx
= (struct gl_context
*) userData
;
1950 _mesa_delete_vao(ctx
, vao
);
1955 * Free vertex array state for given context.
1958 _mesa_free_varray_data(struct gl_context
*ctx
)
1960 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1961 _mesa_DeleteHashTable(ctx
->Array
.Objects
);