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.
29 #include "bufferobj.h"
39 #include "main/dispatch.h"
42 /** Used to do error checking for GL_EXT_vertex_array_bgra */
46 /** Used to indicate which GL datatypes are accepted by each of the
47 * glVertex/Color/Attrib/EtcPointer() functions.
51 #define UNSIGNED_BYTE_BIT 0x4
53 #define UNSIGNED_SHORT_BIT 0x10
55 #define UNSIGNED_INT_BIT 0x40
57 #define FLOAT_BIT 0x100
58 #define DOUBLE_BIT 0x200
59 #define FIXED_ES_BIT 0x400
60 #define FIXED_GL_BIT 0x800
61 #define UNSIGNED_INT_2_10_10_10_REV_BIT 0x1000
62 #define INT_2_10_10_10_REV_BIT 0x2000
63 #define UNSIGNED_INT_10F_11F_11F_REV_BIT 0x4000
66 /** Convert GL datatype enum into a <type>_BIT value seen above */
68 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
75 case GL_UNSIGNED_BYTE
:
76 return UNSIGNED_BYTE_BIT
;
79 case GL_UNSIGNED_SHORT
:
80 return UNSIGNED_SHORT_BIT
;
84 return UNSIGNED_INT_BIT
;
86 if (ctx
->Extensions
.ARB_half_float_vertex
)
95 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
96 case GL_UNSIGNED_INT_2_10_10_10_REV
:
97 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
98 case GL_INT_2_10_10_10_REV
:
99 return INT_2_10_10_10_REV_BIT
;
100 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
101 return UNSIGNED_INT_10F_11F_11F_REV_BIT
;
109 * Sets the VertexBinding field in the vertex attribute given by attribIndex.
112 vertex_attrib_binding(struct gl_context
*ctx
, GLuint attribIndex
,
115 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
116 struct gl_vertex_attrib_array
*array
= &vao
->VertexAttrib
[attribIndex
];
118 if (array
->VertexBinding
!= bindingIndex
) {
119 const GLbitfield64 array_bit
= VERT_BIT(attribIndex
);
121 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
123 vao
->VertexBinding
[array
->VertexBinding
]._BoundArrays
&= ~array_bit
;
124 vao
->VertexBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
126 array
->VertexBinding
= bindingIndex
;
128 vao
->NewArrays
|= array_bit
;
134 * Binds a buffer object to the vertex buffer binding point given by index,
135 * and sets the Offset and Stride fields.
138 bind_vertex_buffer(struct gl_context
*ctx
, GLuint index
,
139 struct gl_buffer_object
*vbo
,
140 GLintptr offset
, GLsizei stride
)
142 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
143 struct gl_vertex_buffer_binding
*binding
= &vao
->VertexBinding
[index
];
145 if (binding
->BufferObj
!= vbo
||
146 binding
->Offset
!= offset
||
147 binding
->Stride
!= stride
) {
149 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
151 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
153 binding
->Offset
= offset
;
154 binding
->Stride
= stride
;
156 vao
->NewArrays
|= binding
->_BoundArrays
;
162 * Sets the InstanceDivisor field in the vertex buffer binding point
163 * given by bindingIndex.
166 vertex_binding_divisor(struct gl_context
*ctx
, GLuint bindingIndex
,
169 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
170 struct gl_vertex_buffer_binding
*binding
=
171 &vao
->VertexBinding
[bindingIndex
];
173 if (binding
->InstanceDivisor
!= divisor
) {
174 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
175 binding
->InstanceDivisor
= divisor
;
176 vao
->NewArrays
|= binding
->_BoundArrays
;
182 * Examine the API profile and extensions to determine which types are legal
183 * for vertex arrays. This is called once from update_array_format().
186 get_legal_types_mask(const struct gl_context
*ctx
)
188 GLbitfield legalTypesMask
= ~0u; /* all */
190 if (_mesa_is_gles(ctx
)) {
191 legalTypesMask
&= ~(FIXED_GL_BIT
|
193 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
195 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
196 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
197 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
198 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
199 * quite as trivial as we'd like because it uses a different enum value
200 * for GL_HALF_FLOAT_OES.
202 if (ctx
->Version
< 30) {
203 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
205 UNSIGNED_INT_2_10_10_10_REV_BIT
|
206 INT_2_10_10_10_REV_BIT
|
211 legalTypesMask
&= ~FIXED_ES_BIT
;
213 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
214 legalTypesMask
&= ~FIXED_GL_BIT
;
216 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
217 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
218 INT_2_10_10_10_REV_BIT
);
220 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
221 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
224 return legalTypesMask
;
229 * Does error checking and updates the format in an attrib array.
231 * Called by update_array() and VertexAttrib*Format().
233 * \param func Name of calling function used for error reporting
234 * \param attrib The index of the attribute array
235 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
236 * \param sizeMin Min allowable size value
237 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
238 * \param size Components per element (1, 2, 3 or 4)
239 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
240 * \param normalized Whether integer types are converted to floats in [-1, 1]
241 * \param integer Integer-valued values (will not be normalized to [-1, 1])
242 * \param relativeOffset Offset of the first element relative to the binding offset.
245 update_array_format(struct gl_context
*ctx
,
247 GLuint attrib
, GLbitfield legalTypesMask
,
248 GLint sizeMin
, GLint sizeMax
,
249 GLint size
, GLenum type
,
250 GLboolean normalized
, GLboolean integer
,
251 GLuint relativeOffset
)
253 struct gl_vertex_attrib_array
*array
;
256 GLenum format
= GL_RGBA
;
258 if (ctx
->Array
.LegalTypesMask
== 0) {
259 /* One-time initialization. We can't do this in _mesa_init_varrays()
260 * below because extensions are not yet enabled at that point.
262 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
265 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
267 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
268 /* BGRA ordering is not supported in ES contexts.
273 typeBit
= type_to_bit(ctx
, type
);
274 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
275 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
276 func
, _mesa_lookup_enum_by_nr(type
));
280 /* Do size parameter checking.
281 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
282 * must be handled specially.
284 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
285 sizeMax
== BGRA_OR_4
&&
287 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
289 * "An INVALID_OPERATION error is generated under any of the following
292 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
293 * or UNSIGNED_INT_2_10_10_10_REV;
295 * • size is BGRA and normalized is FALSE;"
297 bool bgra_error
= false;
299 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
300 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
301 type
!= GL_INT_2_10_10_10_REV
&&
302 type
!= GL_UNSIGNED_BYTE
)
304 } else if (type
!= GL_UNSIGNED_BYTE
)
308 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
309 func
, _mesa_lookup_enum_by_nr(type
));
314 _mesa_error(ctx
, GL_INVALID_OPERATION
,
315 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
322 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
323 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
327 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
328 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
329 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
330 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
334 /* The ARB_vertex_attrib_binding_spec says:
336 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
337 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
339 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
340 _mesa_error(ctx
, GL_INVALID_VALUE
,
341 "%s(relativeOffset=%d > "
342 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
343 func
, relativeOffset
);
347 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
348 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
349 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
355 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
356 assert(elementSize
!= -1);
358 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
361 array
->Format
= format
;
362 array
->Normalized
= normalized
;
363 array
->Integer
= integer
;
364 array
->RelativeOffset
= relativeOffset
;
365 array
->_ElementSize
= elementSize
;
367 ctx
->Array
.VAO
->NewArrays
|= VERT_BIT(attrib
);
368 ctx
->NewState
|= _NEW_ARRAY
;
375 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
378 * \param func name of calling function used for error reporting
379 * \param attrib the attribute array index to update
380 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
381 * \param sizeMin min allowable size value
382 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
383 * \param size components per element (1, 2, 3 or 4)
384 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
385 * \param stride stride between elements, in elements
386 * \param normalized are integer types converted to floats in [-1, 1]?
387 * \param integer integer-valued values (will not be normalized to [-1,1])
388 * \param ptr the address (or offset inside VBO) of the array data
391 update_array(struct gl_context
*ctx
,
393 GLuint attrib
, GLbitfield legalTypesMask
,
394 GLint sizeMin
, GLint sizeMax
,
395 GLint size
, GLenum type
, GLsizei stride
,
396 GLboolean normalized
, GLboolean integer
,
399 struct gl_vertex_attrib_array
*array
;
400 GLsizei effectiveStride
;
402 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
404 * "Client vertex arrays - all vertex array attribute pointers must
405 * refer to buffer objects (section 2.9.2). The default vertex array
406 * object (the name zero) is also deprecated. Calling
407 * VertexAttribPointer when no buffer object or no vertex array object
408 * is bound will generate an INVALID_OPERATION error..."
410 * The check for VBOs is handled below.
412 if (ctx
->API
== API_OPENGL_CORE
413 && (ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
)) {
414 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
420 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
424 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
426 * "An INVALID_OPERATION error is generated under any of the following
431 * * any of the *Pointer commands specifying the location and
432 * organization of vertex array data are called while zero is bound
433 * to the ARRAY_BUFFER buffer object binding point (see section
434 * 2.9.6), and the pointer argument is not NULL."
436 if (ptr
!= NULL
&& ctx
->Array
.VAO
->ARBsemantics
&&
437 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
438 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
442 if (!update_array_format(ctx
, func
, attrib
, legalTypesMask
, sizeMin
,
443 sizeMax
, size
, type
, normalized
, integer
, 0)) {
447 /* Reset the vertex attrib binding */
448 vertex_attrib_binding(ctx
, attrib
, attrib
);
450 /* The Stride and Ptr fields are not set by update_array_format() */
451 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
452 array
->Stride
= stride
;
453 array
->Ptr
= (const GLvoid
*) ptr
;
455 /* Update the vertex buffer binding */
456 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
457 bind_vertex_buffer(ctx
, attrib
, ctx
->Array
.ArrayBufferObj
,
458 (GLintptr
) ptr
, effectiveStride
);
463 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
465 GET_CURRENT_CONTEXT(ctx
);
466 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
467 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
468 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
469 DOUBLE_BIT
| HALF_BIT
|
470 UNSIGNED_INT_2_10_10_10_REV_BIT
|
471 INT_2_10_10_10_REV_BIT
);
473 FLUSH_VERTICES(ctx
, 0);
475 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
477 size
, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
482 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
484 GET_CURRENT_CONTEXT(ctx
);
485 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
486 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
487 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
488 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
489 UNSIGNED_INT_2_10_10_10_REV_BIT
|
490 INT_2_10_10_10_REV_BIT
);
492 FLUSH_VERTICES(ctx
, 0);
494 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
496 3, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
501 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
503 GET_CURRENT_CONTEXT(ctx
);
504 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
505 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
506 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
507 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
508 INT_BIT
| UNSIGNED_INT_BIT
|
509 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
510 UNSIGNED_INT_2_10_10_10_REV_BIT
|
511 INT_2_10_10_10_REV_BIT
);
512 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
514 FLUSH_VERTICES(ctx
, 0);
516 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
517 legalTypes
, sizeMin
, BGRA_OR_4
,
518 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
523 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
525 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
526 GET_CURRENT_CONTEXT(ctx
);
528 FLUSH_VERTICES(ctx
, 0);
530 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
532 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
537 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
539 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
540 FLOAT_BIT
| DOUBLE_BIT
);
541 GET_CURRENT_CONTEXT(ctx
);
543 FLUSH_VERTICES(ctx
, 0);
545 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
547 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
552 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
553 GLsizei stride
, const GLvoid
*ptr
)
555 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
556 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
557 INT_BIT
| UNSIGNED_INT_BIT
|
558 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
559 UNSIGNED_INT_2_10_10_10_REV_BIT
|
560 INT_2_10_10_10_REV_BIT
);
561 GET_CURRENT_CONTEXT(ctx
);
563 FLUSH_VERTICES(ctx
, 0);
565 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
566 legalTypes
, 3, BGRA_OR_4
,
567 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
572 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
575 GET_CURRENT_CONTEXT(ctx
);
576 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
577 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
578 : (SHORT_BIT
| INT_BIT
|
579 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
580 UNSIGNED_INT_2_10_10_10_REV_BIT
|
581 INT_2_10_10_10_REV_BIT
);
582 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
583 const GLuint unit
= ctx
->Array
.ActiveTexture
;
585 FLUSH_VERTICES(ctx
, 0);
587 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
588 legalTypes
, sizeMin
, 4,
589 size
, type
, stride
, GL_FALSE
, GL_FALSE
,
595 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
597 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
598 /* this is the same type that glEdgeFlag uses */
599 const GLboolean integer
= GL_FALSE
;
600 GET_CURRENT_CONTEXT(ctx
);
602 FLUSH_VERTICES(ctx
, 0);
604 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
606 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, ptr
);
611 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
613 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
614 GET_CURRENT_CONTEXT(ctx
);
616 FLUSH_VERTICES(ctx
, 0);
618 if (ctx
->API
!= API_OPENGLES
) {
619 _mesa_error(ctx
, GL_INVALID_OPERATION
,
620 "glPointSizePointer(ES 1.x only)");
624 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
626 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
631 * Set a generic vertex attribute array.
632 * Note that these arrays DO NOT alias the conventional GL vertex arrays
633 * (position, normal, color, fog, texcoord, etc).
636 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
637 GLboolean normalized
,
638 GLsizei stride
, const GLvoid
*ptr
)
640 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
641 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
642 INT_BIT
| UNSIGNED_INT_BIT
|
643 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
644 FIXED_ES_BIT
| FIXED_GL_BIT
|
645 UNSIGNED_INT_2_10_10_10_REV_BIT
|
646 INT_2_10_10_10_REV_BIT
|
647 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
648 GET_CURRENT_CONTEXT(ctx
);
650 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
651 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
655 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
656 legalTypes
, 1, BGRA_OR_4
,
657 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
662 * GL_EXT_gpu_shader4 / GL 3.0.
663 * Set an integer-valued vertex attribute array.
664 * Note that these arrays DO NOT alias the conventional GL vertex arrays
665 * (position, normal, color, fog, texcoord, etc).
668 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
669 GLsizei stride
, const GLvoid
*ptr
)
671 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
672 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
673 INT_BIT
| UNSIGNED_INT_BIT
);
674 const GLboolean normalized
= GL_FALSE
;
675 const GLboolean integer
= GL_TRUE
;
676 GET_CURRENT_CONTEXT(ctx
);
678 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
679 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
683 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
685 size
, type
, stride
, normalized
, integer
, ptr
);
691 _mesa_EnableVertexAttribArray(GLuint index
)
693 struct gl_vertex_array_object
*vao
;
694 GET_CURRENT_CONTEXT(ctx
);
696 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
697 _mesa_error(ctx
, GL_INVALID_VALUE
,
698 "glEnableVertexAttribArrayARB(index)");
702 vao
= ctx
->Array
.VAO
;
704 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(vao
->_VertexAttrib
));
706 if (!vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
707 /* was disabled, now being enabled */
708 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
709 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
710 vao
->_Enabled
|= VERT_BIT_GENERIC(index
);
711 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
717 _mesa_DisableVertexAttribArray(GLuint index
)
719 struct gl_vertex_array_object
*vao
;
720 GET_CURRENT_CONTEXT(ctx
);
722 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
723 _mesa_error(ctx
, GL_INVALID_VALUE
,
724 "glDisableVertexAttribArrayARB(index)");
728 vao
= ctx
->Array
.VAO
;
730 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(vao
->_VertexAttrib
));
732 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
733 /* was enabled, now being disabled */
734 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
735 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
736 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
737 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
743 * Return info for a vertex attribute array (no alias with legacy
744 * vertex attributes (pos, normal, color, etc)). This function does
745 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
748 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
751 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
752 const struct gl_vertex_attrib_array
*array
;
754 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
755 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
759 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(vao
->VertexAttrib
));
761 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
764 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
765 return array
->Enabled
;
766 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
767 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
768 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
769 return array
->Stride
;
770 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
772 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
773 return array
->Normalized
;
774 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
775 return vao
->VertexBinding
[array
->VertexBinding
].BufferObj
->Name
;
776 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
777 if ((_mesa_is_desktop_gl(ctx
)
778 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
779 || _mesa_is_gles3(ctx
)) {
780 return array
->Integer
;
783 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
784 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
785 || _mesa_is_gles3(ctx
)) {
786 return vao
->VertexBinding
[array
->VertexBinding
].InstanceDivisor
;
789 case GL_VERTEX_ATTRIB_BINDING
:
790 if (_mesa_is_desktop_gl(ctx
)) {
791 return array
->VertexBinding
- VERT_ATTRIB_GENERIC0
;
794 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
795 if (_mesa_is_desktop_gl(ctx
)) {
796 return array
->RelativeOffset
;
804 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
809 static const GLfloat
*
810 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
813 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
814 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
818 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
819 _mesa_error(ctx
, GL_INVALID_VALUE
,
820 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
824 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.VAO
->_VertexAttrib
));
826 FLUSH_CURRENT(ctx
, 0);
827 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
831 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
833 GET_CURRENT_CONTEXT(ctx
);
835 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
836 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
842 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
843 "glGetVertexAttribfv");
849 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
851 GET_CURRENT_CONTEXT(ctx
);
853 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
854 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
856 params
[0] = (GLdouble
) v
[0];
857 params
[1] = (GLdouble
) v
[1];
858 params
[2] = (GLdouble
) v
[2];
859 params
[3] = (GLdouble
) v
[3];
863 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
864 "glGetVertexAttribdv");
870 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
872 GET_CURRENT_CONTEXT(ctx
);
874 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
875 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
877 /* XXX should floats in[0,1] be scaled to full int range? */
878 params
[0] = (GLint
) v
[0];
879 params
[1] = (GLint
) v
[1];
880 params
[2] = (GLint
) v
[2];
881 params
[3] = (GLint
) v
[3];
885 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
886 "glGetVertexAttribiv");
893 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
895 GET_CURRENT_CONTEXT(ctx
);
897 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
898 const GLint
*v
= (const GLint
*)
899 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
905 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
906 "glGetVertexAttribIiv");
913 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
915 GET_CURRENT_CONTEXT(ctx
);
917 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
918 const GLuint
*v
= (const GLuint
*)
919 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
925 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
926 "glGetVertexAttribIuiv");
932 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
934 GET_CURRENT_CONTEXT(ctx
);
936 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
937 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
941 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
942 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
946 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.VAO
->_VertexAttrib
));
948 *pointer
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
953 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
954 GLsizei count
, const GLvoid
*ptr
)
957 _mesa_VertexPointer(size
, type
, stride
, ptr
);
962 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
966 _mesa_NormalPointer(type
, stride
, ptr
);
971 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
975 _mesa_ColorPointer(size
, type
, stride
, ptr
);
980 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
984 _mesa_IndexPointer(type
, stride
, ptr
);
989 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
990 GLsizei count
, const GLvoid
*ptr
)
993 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
998 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1001 _mesa_EdgeFlagPointer(stride
, ptr
);
1006 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1008 GET_CURRENT_CONTEXT(ctx
);
1009 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1010 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1011 GLenum ctype
= 0; /* color type */
1012 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1013 const GLint toffset
= 0; /* always zero */
1014 GLint defstride
; /* default stride */
1017 FLUSH_VERTICES(ctx
, 0);
1019 f
= sizeof(GLfloat
);
1020 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1023 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1029 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1030 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1035 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1036 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1041 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1042 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1043 ctype
= GL_UNSIGNED_BYTE
;
1046 defstride
= c
+ 2*f
;
1049 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1050 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1051 ctype
= GL_UNSIGNED_BYTE
;
1054 defstride
= c
+ 3*f
;
1057 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1058 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1065 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1066 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1071 case GL_C4F_N3F_V3F
:
1072 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1073 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1081 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1082 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1087 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1088 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1092 case GL_T2F_C4UB_V3F
:
1093 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1094 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1095 ctype
= GL_UNSIGNED_BYTE
;
1100 case GL_T2F_C3F_V3F
:
1101 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1102 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1108 case GL_T2F_N3F_V3F
:
1109 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1110 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1115 case GL_T2F_C4F_N3F_V3F
:
1116 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1117 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1124 case GL_T4F_C4F_N3F_V4F
:
1125 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1126 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1134 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1142 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1143 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1144 /* XXX also disable secondary color and generic arrays? */
1148 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1149 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1150 (GLubyte
*) pointer
+ toffset
);
1153 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1158 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1159 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1160 (GLubyte
*) pointer
+ coffset
);
1163 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1169 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1170 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1173 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1177 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1178 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1179 (GLubyte
*) pointer
+ voffset
);
1184 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1186 GET_CURRENT_CONTEXT(ctx
);
1188 FLUSH_VERTICES(ctx
, 0);
1190 if (MESA_VERBOSE
& VERBOSE_API
)
1191 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1194 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1198 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1201 if (ctx
->Array
.LockCount
!= 0) {
1202 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1206 ctx
->Array
.LockFirst
= first
;
1207 ctx
->Array
.LockCount
= count
;
1209 ctx
->NewState
|= _NEW_ARRAY
;
1214 _mesa_UnlockArraysEXT( void )
1216 GET_CURRENT_CONTEXT(ctx
);
1218 FLUSH_VERTICES(ctx
, 0);
1220 if (MESA_VERBOSE
& VERBOSE_API
)
1221 _mesa_debug(ctx
, "glUnlockArrays\n");
1223 if (ctx
->Array
.LockCount
== 0) {
1224 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1228 ctx
->Array
.LockFirst
= 0;
1229 ctx
->Array
.LockCount
= 0;
1230 ctx
->NewState
|= _NEW_ARRAY
;
1234 /* GL_EXT_multi_draw_arrays */
1236 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1237 const GLsizei
*count
, GLsizei primcount
)
1239 GET_CURRENT_CONTEXT(ctx
);
1242 FLUSH_VERTICES(ctx
, 0);
1244 for (i
= 0; i
< primcount
; i
++) {
1246 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1252 /* GL_IBM_multimode_draw_arrays */
1254 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1255 const GLsizei
* count
,
1256 GLsizei primcount
, GLint modestride
)
1258 GET_CURRENT_CONTEXT(ctx
);
1261 FLUSH_VERTICES(ctx
, 0);
1263 for ( i
= 0 ; i
< primcount
; i
++ ) {
1264 if ( count
[i
] > 0 ) {
1265 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1266 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1272 /* GL_IBM_multimode_draw_arrays */
1274 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1275 GLenum type
, const GLvoid
* const * indices
,
1276 GLsizei primcount
, GLint modestride
)
1278 GET_CURRENT_CONTEXT(ctx
);
1281 FLUSH_VERTICES(ctx
, 0);
1283 /* XXX not sure about ARB_vertex_buffer_object handling here */
1285 for ( i
= 0 ; i
< primcount
; i
++ ) {
1286 if ( count
[i
] > 0 ) {
1287 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1288 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1296 * GL_NV_primitive_restart and GL 3.1
1299 _mesa_PrimitiveRestartIndex(GLuint index
)
1301 GET_CURRENT_CONTEXT(ctx
);
1303 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1304 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1308 if (ctx
->Array
.RestartIndex
!= index
) {
1309 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1310 ctx
->Array
.RestartIndex
= index
;
1316 * See GL_ARB_instanced_arrays.
1317 * Note that the instance divisor only applies to generic arrays, not
1318 * the legacy vertex arrays.
1321 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1323 GET_CURRENT_CONTEXT(ctx
);
1325 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1327 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1328 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1332 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1333 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1338 ASSERT(genericIndex
< Elements(ctx
->Array
.VAO
->VertexAttrib
));
1340 /* The ARB_vertex_attrib_binding spec says:
1344 * void VertexAttribDivisor(uint index, uint divisor);
1346 * is equivalent to (assuming no errors are generated):
1348 * VertexAttribBinding(index, index);
1349 * VertexBindingDivisor(index, divisor);"
1351 vertex_attrib_binding(ctx
, genericIndex
, genericIndex
);
1352 vertex_binding_divisor(ctx
, genericIndex
, divisor
);
1357 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1359 /* From the OpenGL 4.3 core specification, page 302:
1360 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1361 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1364 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1366 case GL_UNSIGNED_BYTE
:
1368 case GL_UNSIGNED_SHORT
:
1370 case GL_UNSIGNED_INT
:
1373 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1377 return ctx
->Array
.RestartIndex
;
1382 * GL_ARB_vertex_attrib_binding
1385 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1388 GET_CURRENT_CONTEXT(ctx
);
1389 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1390 struct gl_buffer_object
*vbo
;
1392 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1394 /* The ARB_vertex_attrib_binding spec says:
1396 * "An INVALID_OPERATION error is generated if no vertex array object
1399 if (ctx
->API
== API_OPENGL_CORE
&&
1400 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1401 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1402 "glBindVertexBuffer(No array object bound)");
1406 /* The ARB_vertex_attrib_binding spec says:
1408 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1409 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1411 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1412 _mesa_error(ctx
, GL_INVALID_VALUE
,
1413 "glBindVertexBuffer(bindingindex=%u > "
1414 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1419 /* The ARB_vertex_attrib_binding spec says:
1421 * "The error INVALID_VALUE is generated if <stride> or <offset>
1425 _mesa_error(ctx
, GL_INVALID_VALUE
,
1426 "glBindVertexBuffer(offset=%lld < 0)", (long long)offset
);
1431 _mesa_error(ctx
, GL_INVALID_VALUE
,
1432 "glBindVertexBuffer(stride=%d < 0)", stride
);
1436 if (buffer
== vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1437 vbo
= vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1438 } else if (buffer
!= 0) {
1439 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1441 /* From the GL_ARB_vertex_attrib_array spec:
1443 * "[Core profile only:]
1444 * An INVALID_OPERATION error is generated if buffer is not zero or a
1445 * name returned from a previous call to GenBuffers, or if such a name
1446 * has since been deleted with DeleteBuffers.
1448 * Otherwise, we fall back to the same compat profile behavior as other
1449 * object references (automatically gen it).
1451 if (!_mesa_handle_bind_buffer_gen(ctx
, GL_ARRAY_BUFFER
, buffer
,
1452 &vbo
, "glBindVertexBuffer"))
1455 /* The ARB_vertex_attrib_binding spec says:
1457 * "If <buffer> is zero, any buffer object attached to this
1458 * bindpoint is detached."
1460 vbo
= ctx
->Shared
->NullBufferObj
;
1463 bind_vertex_buffer(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
),
1464 vbo
, offset
, stride
);
1469 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1470 const GLintptr
*offsets
, const GLsizei
*strides
)
1472 GET_CURRENT_CONTEXT(ctx
);
1473 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1476 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1478 /* The ARB_vertex_attrib_binding spec says:
1480 * "An INVALID_OPERATION error is generated if no
1481 * vertex array object is bound."
1483 if (ctx
->API
== API_OPENGL_CORE
&&
1484 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1485 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1486 "glBindVertexBuffers(No array object bound)");
1490 /* The ARB_multi_bind spec says:
1492 * "An INVALID_OPERATION error is generated if <first> + <count>
1493 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1495 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1496 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1497 "glBindVertexBuffers(first=%u + count=%d > the value of "
1498 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1499 first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1505 * The ARB_multi_bind spec says:
1507 * "If <buffers> is NULL, each affected vertex buffer binding point
1508 * from <first> through <first>+<count>-1 will be reset to have no
1509 * bound buffer object. In this case, the offsets and strides
1510 * associated with the binding points are set to default values,
1511 * ignoring <offsets> and <strides>."
1513 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1515 for (i
= 0; i
< count
; i
++)
1516 bind_vertex_buffer(ctx
, VERT_ATTRIB_GENERIC(first
+ i
), vbo
, 0, 16);
1521 /* Note that the error semantics for multi-bind commands differ from
1522 * those of other GL commands.
1524 * The Issues section in the ARB_multi_bind spec says:
1526 * "(11) Typically, OpenGL specifies that if an error is generated by
1527 * a command, that command has no effect. This is somewhat
1528 * unfortunate for multi-bind commands, because it would require
1529 * a first pass to scan the entire list of bound objects for
1530 * errors and then a second pass to actually perform the
1531 * bindings. Should we have different error semantics?
1533 * RESOLVED: Yes. In this specification, when the parameters for
1534 * one of the <count> binding points are invalid, that binding
1535 * point is not updated and an error will be generated. However,
1536 * other binding points in the same command will be updated if
1537 * their parameters are valid and no other error occurs."
1540 _mesa_begin_bufferobj_lookups(ctx
);
1542 for (i
= 0; i
< count
; i
++) {
1543 struct gl_buffer_object
*vbo
;
1545 /* The ARB_multi_bind spec says:
1547 * "An INVALID_VALUE error is generated if any value in
1548 * <offsets> or <strides> is negative (per binding)."
1550 if (offsets
[i
] < 0) {
1551 _mesa_error(ctx
, GL_INVALID_VALUE
,
1552 "glBindVertexBuffer(offsets[%u]=%lldd < 0)",
1553 i
, (long long int) offsets
[i
]);
1557 if (strides
[i
] < 0) {
1558 _mesa_error(ctx
, GL_INVALID_VALUE
,
1559 "glBindVertexBuffer(strides[%u]=%lld < 0)",
1560 i
, (long long int) strides
[i
]);
1565 struct gl_vertex_buffer_binding
*binding
=
1566 &vao
->VertexBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1568 if (buffers
[i
] == binding
->BufferObj
->Name
)
1569 vbo
= binding
->BufferObj
;
1571 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
1572 "glBindVertexBuffers");
1577 vbo
= ctx
->Shared
->NullBufferObj
;
1580 bind_vertex_buffer(ctx
, VERT_ATTRIB_GENERIC(first
+ i
), vbo
,
1581 offsets
[i
], strides
[i
]);
1584 _mesa_end_bufferobj_lookups(ctx
);
1589 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1590 GLboolean normalized
, GLuint relativeOffset
)
1592 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1593 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1594 INT_BIT
| UNSIGNED_INT_BIT
|
1595 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1597 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1598 INT_2_10_10_10_REV_BIT
|
1599 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1601 GET_CURRENT_CONTEXT(ctx
);
1602 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1604 /* The ARB_vertex_attrib_binding spec says:
1606 * "An INVALID_OPERATION error is generated under any of the following
1608 * - if no vertex array object is currently bound (see section 2.10);
1611 if (ctx
->API
== API_OPENGL_CORE
&&
1612 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1613 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1614 "glVertexAttribFormat(No array object bound)");
1618 /* The ARB_vertex_attrib_binding spec says:
1620 * "The error INVALID_VALUE is generated if index is greater than or equal
1621 * to the value of MAX_VERTEX_ATTRIBS."
1623 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1624 _mesa_error(ctx
, GL_INVALID_VALUE
,
1625 "glVertexAttribFormat(attribindex=%u > "
1626 "GL_MAX_VERTEX_ATTRIBS)",
1631 FLUSH_VERTICES(ctx
, 0);
1633 update_array_format(ctx
, "glVertexAttribFormat",
1634 VERT_ATTRIB_GENERIC(attribIndex
),
1635 legalTypes
, 1, BGRA_OR_4
, size
, type
, normalized
,
1636 GL_FALSE
, relativeOffset
);
1641 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1642 GLuint relativeOffset
)
1644 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1645 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1646 INT_BIT
| UNSIGNED_INT_BIT
);
1648 GET_CURRENT_CONTEXT(ctx
);
1649 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1651 /* The ARB_vertex_attrib_binding spec says:
1653 * "An INVALID_OPERATION error is generated under any of the following
1655 * - if no vertex array object is currently bound (see section 2.10);
1658 if (ctx
->API
== API_OPENGL_CORE
&&
1659 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1660 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1661 "glVertexAttribIFormat(No array object bound)");
1665 /* The ARB_vertex_attrib_binding spec says:
1667 * "The error INVALID_VALUE is generated if index is greater than
1668 * or equal to the value of MAX_VERTEX_ATTRIBS."
1670 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1671 _mesa_error(ctx
, GL_INVALID_VALUE
,
1672 "glVertexAttribIFormat(attribindex=%u > "
1673 "GL_MAX_VERTEX_ATTRIBS)",
1678 FLUSH_VERTICES(ctx
, 0);
1680 update_array_format(ctx
, "glVertexAttribIFormat",
1681 VERT_ATTRIB_GENERIC(attribIndex
),
1682 legalTypes
, 1, 4, size
, type
, GL_FALSE
, GL_TRUE
,
1688 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1689 GLuint relativeOffset
)
1691 const GLbitfield legalTypes
= DOUBLE_BIT
;
1693 GET_CURRENT_CONTEXT(ctx
);
1694 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1696 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
1698 * "An INVALID_OPERATION error is generated under any of the following
1700 * • if no vertex array object is currently bound (see section 10.4);
1703 * This language is missing from the extension spec, but we assume
1704 * that this is an oversight.
1706 if (ctx
->API
== API_OPENGL_CORE
&&
1707 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1708 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1709 "glVertexAttribLFormat(No array object bound)");
1713 /* The ARB_vertex_attrib_binding spec says:
1715 * "The error INVALID_VALUE is generated if <attribindex> is greater than
1716 * or equal to the value of MAX_VERTEX_ATTRIBS."
1718 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1719 _mesa_error(ctx
, GL_INVALID_VALUE
,
1720 "glVertexAttribLFormat(attribindex=%u > "
1721 "GL_MAX_VERTEX_ATTRIBS)",
1726 FLUSH_VERTICES(ctx
, 0);
1728 update_array_format(ctx
, "glVertexAttribLFormat",
1729 VERT_ATTRIB_GENERIC(attribIndex
),
1730 legalTypes
, 1, 4, size
, type
, GL_FALSE
, GL_FALSE
,
1736 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
1738 GET_CURRENT_CONTEXT(ctx
);
1739 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1741 /* The ARB_vertex_attrib_binding spec says:
1743 * "An INVALID_OPERATION error is generated if no vertex array object
1746 if (ctx
->API
== API_OPENGL_CORE
&&
1747 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1748 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1749 "glVertexAttribBinding(No array object bound)");
1753 /* The ARB_vertex_attrib_binding spec says:
1755 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1756 * <bindingindex> must be less than the value of
1757 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1760 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1761 _mesa_error(ctx
, GL_INVALID_VALUE
,
1762 "glVertexAttribBinding(attribindex=%u >= "
1763 "GL_MAX_VERTEX_ATTRIBS)",
1768 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1769 _mesa_error(ctx
, GL_INVALID_VALUE
,
1770 "glVertexAttribBinding(bindingindex=%u >= "
1771 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1776 ASSERT(VERT_ATTRIB_GENERIC(attribIndex
) <
1777 Elements(ctx
->Array
.VAO
->VertexAttrib
));
1779 vertex_attrib_binding(ctx
, VERT_ATTRIB_GENERIC(attribIndex
),
1780 VERT_ATTRIB_GENERIC(bindingIndex
));
1785 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
1787 GET_CURRENT_CONTEXT(ctx
);
1788 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1790 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1791 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexBindingDivisor()");
1795 /* The ARB_vertex_attrib_binding spec says:
1797 * "An INVALID_OPERATION error is generated if no vertex array object
1800 if (ctx
->API
== API_OPENGL_CORE
&&
1801 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1802 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1803 "glVertexBindingDivisor(No array object bound)");
1807 /* The ARB_vertex_attrib_binding spec says:
1809 * "An INVALID_VALUE error is generated if <bindingindex> is greater
1810 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
1812 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1813 _mesa_error(ctx
, GL_INVALID_VALUE
,
1814 "glVertexBindingDivisor(bindingindex=%u > "
1815 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1820 vertex_binding_divisor(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
1825 * Copy one client vertex array to another.
1828 _mesa_copy_client_array(struct gl_context
*ctx
,
1829 struct gl_client_array
*dst
,
1830 struct gl_client_array
*src
)
1832 dst
->Size
= src
->Size
;
1833 dst
->Type
= src
->Type
;
1834 dst
->Format
= src
->Format
;
1835 dst
->Stride
= src
->Stride
;
1836 dst
->StrideB
= src
->StrideB
;
1837 dst
->Ptr
= src
->Ptr
;
1838 dst
->Enabled
= src
->Enabled
;
1839 dst
->Normalized
= src
->Normalized
;
1840 dst
->Integer
= src
->Integer
;
1841 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1842 dst
->_ElementSize
= src
->_ElementSize
;
1843 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1844 dst
->_MaxElement
= src
->_MaxElement
;
1848 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
1849 struct gl_vertex_attrib_array
*dst
,
1850 const struct gl_vertex_attrib_array
*src
)
1852 dst
->Size
= src
->Size
;
1853 dst
->Type
= src
->Type
;
1854 dst
->Format
= src
->Format
;
1855 dst
->VertexBinding
= src
->VertexBinding
;
1856 dst
->RelativeOffset
= src
->RelativeOffset
;
1857 dst
->Format
= src
->Format
;
1858 dst
->Integer
= src
->Integer
;
1859 dst
->Normalized
= src
->Normalized
;
1860 dst
->Ptr
= src
->Ptr
;
1861 dst
->Enabled
= src
->Enabled
;
1862 dst
->_ElementSize
= src
->_ElementSize
;
1866 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
1867 struct gl_vertex_buffer_binding
*dst
,
1868 const struct gl_vertex_buffer_binding
*src
)
1870 dst
->Offset
= src
->Offset
;
1871 dst
->Stride
= src
->Stride
;
1872 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1873 dst
->_BoundArrays
= src
->_BoundArrays
;
1875 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1879 * Print vertex array's fields.
1882 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1885 printf(" %s[%d]: ", name
, index
);
1887 printf(" %s: ", name
);
1888 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
1889 array
->Ptr
, array
->Type
, array
->Size
,
1890 array
->_ElementSize
, array
->StrideB
,
1891 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
,
1892 array
->_MaxElement
);
1897 * Print current vertex object/array info. For debug.
1900 _mesa_print_arrays(struct gl_context
*ctx
)
1902 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1905 _mesa_update_vao_max_element(ctx
, vao
);
1907 printf("Array Object %u\n", vao
->Name
);
1908 if (vao
->_VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
1909 print_array("Vertex", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_POS
]);
1910 if (vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
1911 print_array("Normal", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
]);
1912 if (vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
1913 print_array("Color", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
]);
1914 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
1915 if (vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
1916 print_array("TexCoord", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
1917 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
1918 if (vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
1919 print_array("Attrib", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
1920 printf(" _MaxElement = %u\n", vao
->_MaxElement
);
1925 * Initialize vertex array state for given context.
1928 _mesa_init_varray(struct gl_context
*ctx
)
1930 ctx
->Array
.DefaultVAO
= ctx
->Driver
.NewArrayObject(ctx
, 0);
1931 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
1932 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1934 ctx
->Array
.Objects
= _mesa_NewHashTable();
1939 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1942 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1944 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
1945 struct gl_context
*ctx
= (struct gl_context
*) userData
;
1946 _mesa_delete_vao(ctx
, vao
);
1951 * Free vertex array state for given context.
1954 _mesa_free_varray_data(struct gl_context
*ctx
)
1956 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1957 _mesa_DeleteHashTable(ctx
->Array
.Objects
);