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 * Does error checking and updates the format in an attrib array.
184 * Called by update_array() and VertexAttrib*Format().
186 * \param func Name of calling function used for error reporting
187 * \param attrib The index of the attribute array
188 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
189 * \param sizeMin Min allowable size value
190 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
191 * \param size Components per element (1, 2, 3 or 4)
192 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
193 * \param normalized Whether integer types are converted to floats in [-1, 1]
194 * \param integer Integer-valued values (will not be normalized to [-1, 1])
195 * \param relativeOffset Offset of the first element relative to the binding offset.
198 update_array_format(struct gl_context
*ctx
,
200 GLuint attrib
, GLbitfield legalTypesMask
,
201 GLint sizeMin
, GLint sizeMax
,
202 GLint size
, GLenum type
,
203 GLboolean normalized
, GLboolean integer
,
204 GLuint relativeOffset
)
206 struct gl_vertex_attrib_array
*array
;
209 GLenum format
= GL_RGBA
;
211 if (_mesa_is_gles(ctx
)) {
212 legalTypesMask
&= ~(FIXED_GL_BIT
| DOUBLE_BIT
| UNSIGNED_INT_10F_11F_11F_REV_BIT
);
214 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
215 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
216 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
217 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
218 * quite as trivial as we'd like because it uses a different enum value
219 * for GL_HALF_FLOAT_OES.
221 if (ctx
->Version
< 30) {
222 legalTypesMask
&= ~(UNSIGNED_INT_BIT
224 | UNSIGNED_INT_2_10_10_10_REV_BIT
225 | INT_2_10_10_10_REV_BIT
229 /* BGRA ordering is not supported in ES contexts.
231 if (sizeMax
== BGRA_OR_4
)
234 legalTypesMask
&= ~FIXED_ES_BIT
;
236 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
237 legalTypesMask
&= ~FIXED_GL_BIT
;
239 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
240 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
241 INT_2_10_10_10_REV_BIT
);
243 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
244 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
247 typeBit
= type_to_bit(ctx
, type
);
248 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
249 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
250 func
, _mesa_lookup_enum_by_nr(type
));
254 /* Do size parameter checking.
255 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
256 * must be handled specially.
258 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
259 sizeMax
== BGRA_OR_4
&&
261 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
263 * "An INVALID_OPERATION error is generated under any of the following
266 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
267 * or UNSIGNED_INT_2_10_10_10_REV;
269 * • size is BGRA and normalized is FALSE;"
271 bool bgra_error
= false;
273 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
274 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
275 type
!= GL_INT_2_10_10_10_REV
&&
276 type
!= GL_UNSIGNED_BYTE
)
278 } else if (type
!= GL_UNSIGNED_BYTE
)
282 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
283 func
, _mesa_lookup_enum_by_nr(type
));
288 _mesa_error(ctx
, GL_INVALID_OPERATION
,
289 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
296 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
297 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
301 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
302 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
303 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
304 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
308 /* The ARB_vertex_attrib_binding_spec says:
310 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
311 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
313 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
314 _mesa_error(ctx
, GL_INVALID_VALUE
,
315 "%s(relativeOffset=%d > "
316 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
317 func
, relativeOffset
);
321 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
322 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
323 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
329 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
330 assert(elementSize
!= -1);
332 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
335 array
->Format
= format
;
336 array
->Normalized
= normalized
;
337 array
->Integer
= integer
;
338 array
->RelativeOffset
= relativeOffset
;
339 array
->_ElementSize
= elementSize
;
341 ctx
->Array
.VAO
->NewArrays
|= VERT_BIT(attrib
);
342 ctx
->NewState
|= _NEW_ARRAY
;
349 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
352 * \param func name of calling function used for error reporting
353 * \param attrib the attribute array index to update
354 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
355 * \param sizeMin min allowable size value
356 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
357 * \param size components per element (1, 2, 3 or 4)
358 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
359 * \param stride stride between elements, in elements
360 * \param normalized are integer types converted to floats in [-1, 1]?
361 * \param integer integer-valued values (will not be normalized to [-1,1])
362 * \param ptr the address (or offset inside VBO) of the array data
365 update_array(struct gl_context
*ctx
,
367 GLuint attrib
, GLbitfield legalTypesMask
,
368 GLint sizeMin
, GLint sizeMax
,
369 GLint size
, GLenum type
, GLsizei stride
,
370 GLboolean normalized
, GLboolean integer
,
373 struct gl_vertex_attrib_array
*array
;
374 GLsizei effectiveStride
;
376 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
378 * "Client vertex arrays - all vertex array attribute pointers must
379 * refer to buffer objects (section 2.9.2). The default vertex array
380 * object (the name zero) is also deprecated. Calling
381 * VertexAttribPointer when no buffer object or no vertex array object
382 * is bound will generate an INVALID_OPERATION error..."
384 * The check for VBOs is handled below.
386 if (ctx
->API
== API_OPENGL_CORE
387 && (ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
)) {
388 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
394 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
398 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
400 * "An INVALID_OPERATION error is generated under any of the following
405 * * any of the *Pointer commands specifying the location and
406 * organization of vertex array data are called while zero is bound
407 * to the ARRAY_BUFFER buffer object binding point (see section
408 * 2.9.6), and the pointer argument is not NULL."
410 if (ptr
!= NULL
&& ctx
->Array
.VAO
->ARBsemantics
&&
411 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
412 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
416 if (!update_array_format(ctx
, func
, attrib
, legalTypesMask
, sizeMin
,
417 sizeMax
, size
, type
, normalized
, integer
, 0)) {
421 /* Reset the vertex attrib binding */
422 vertex_attrib_binding(ctx
, attrib
, attrib
);
424 /* The Stride and Ptr fields are not set by update_array_format() */
425 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
426 array
->Stride
= stride
;
427 array
->Ptr
= (const GLvoid
*) ptr
;
429 /* Update the vertex buffer binding */
430 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
431 bind_vertex_buffer(ctx
, attrib
, ctx
->Array
.ArrayBufferObj
,
432 (GLintptr
) ptr
, effectiveStride
);
437 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
439 GET_CURRENT_CONTEXT(ctx
);
440 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
441 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
442 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
443 DOUBLE_BIT
| HALF_BIT
|
444 UNSIGNED_INT_2_10_10_10_REV_BIT
|
445 INT_2_10_10_10_REV_BIT
);
447 FLUSH_VERTICES(ctx
, 0);
449 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
451 size
, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
456 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
458 GET_CURRENT_CONTEXT(ctx
);
459 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
460 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
461 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
462 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
463 UNSIGNED_INT_2_10_10_10_REV_BIT
|
464 INT_2_10_10_10_REV_BIT
);
466 FLUSH_VERTICES(ctx
, 0);
468 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
470 3, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
475 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
477 GET_CURRENT_CONTEXT(ctx
);
478 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
479 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
480 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
481 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
482 INT_BIT
| UNSIGNED_INT_BIT
|
483 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
484 UNSIGNED_INT_2_10_10_10_REV_BIT
|
485 INT_2_10_10_10_REV_BIT
);
486 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
488 FLUSH_VERTICES(ctx
, 0);
490 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
491 legalTypes
, sizeMin
, BGRA_OR_4
,
492 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
497 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
499 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
500 GET_CURRENT_CONTEXT(ctx
);
502 FLUSH_VERTICES(ctx
, 0);
504 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
506 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
511 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
513 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
514 FLOAT_BIT
| DOUBLE_BIT
);
515 GET_CURRENT_CONTEXT(ctx
);
517 FLUSH_VERTICES(ctx
, 0);
519 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
521 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
526 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
527 GLsizei stride
, const GLvoid
*ptr
)
529 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
530 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
531 INT_BIT
| UNSIGNED_INT_BIT
|
532 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
533 UNSIGNED_INT_2_10_10_10_REV_BIT
|
534 INT_2_10_10_10_REV_BIT
);
535 GET_CURRENT_CONTEXT(ctx
);
537 FLUSH_VERTICES(ctx
, 0);
539 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
540 legalTypes
, 3, BGRA_OR_4
,
541 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
546 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
549 GET_CURRENT_CONTEXT(ctx
);
550 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
551 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
552 : (SHORT_BIT
| INT_BIT
|
553 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
554 UNSIGNED_INT_2_10_10_10_REV_BIT
|
555 INT_2_10_10_10_REV_BIT
);
556 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
557 const GLuint unit
= ctx
->Array
.ActiveTexture
;
559 FLUSH_VERTICES(ctx
, 0);
561 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
562 legalTypes
, sizeMin
, 4,
563 size
, type
, stride
, GL_FALSE
, GL_FALSE
,
569 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
571 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
572 /* this is the same type that glEdgeFlag uses */
573 const GLboolean integer
= GL_FALSE
;
574 GET_CURRENT_CONTEXT(ctx
);
576 FLUSH_VERTICES(ctx
, 0);
578 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
580 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, ptr
);
585 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
587 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
588 GET_CURRENT_CONTEXT(ctx
);
590 FLUSH_VERTICES(ctx
, 0);
592 if (ctx
->API
!= API_OPENGLES
) {
593 _mesa_error(ctx
, GL_INVALID_OPERATION
,
594 "glPointSizePointer(ES 1.x only)");
598 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
600 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
605 * Set a generic vertex attribute array.
606 * Note that these arrays DO NOT alias the conventional GL vertex arrays
607 * (position, normal, color, fog, texcoord, etc).
610 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
611 GLboolean normalized
,
612 GLsizei stride
, const GLvoid
*ptr
)
614 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
615 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
616 INT_BIT
| UNSIGNED_INT_BIT
|
617 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
618 FIXED_ES_BIT
| FIXED_GL_BIT
|
619 UNSIGNED_INT_2_10_10_10_REV_BIT
|
620 INT_2_10_10_10_REV_BIT
|
621 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
622 GET_CURRENT_CONTEXT(ctx
);
624 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
625 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
629 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
630 legalTypes
, 1, BGRA_OR_4
,
631 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
636 * GL_EXT_gpu_shader4 / GL 3.0.
637 * Set an integer-valued vertex attribute array.
638 * Note that these arrays DO NOT alias the conventional GL vertex arrays
639 * (position, normal, color, fog, texcoord, etc).
642 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
643 GLsizei stride
, const GLvoid
*ptr
)
645 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
646 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
647 INT_BIT
| UNSIGNED_INT_BIT
);
648 const GLboolean normalized
= GL_FALSE
;
649 const GLboolean integer
= GL_TRUE
;
650 GET_CURRENT_CONTEXT(ctx
);
652 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
653 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
657 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
659 size
, type
, stride
, normalized
, integer
, ptr
);
665 _mesa_EnableVertexAttribArray(GLuint index
)
667 struct gl_vertex_array_object
*vao
;
668 GET_CURRENT_CONTEXT(ctx
);
670 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
671 _mesa_error(ctx
, GL_INVALID_VALUE
,
672 "glEnableVertexAttribArrayARB(index)");
676 vao
= ctx
->Array
.VAO
;
678 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(vao
->_VertexAttrib
));
680 if (!vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
681 /* was disabled, now being enabled */
682 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
683 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
684 vao
->_Enabled
|= VERT_BIT_GENERIC(index
);
685 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
691 _mesa_DisableVertexAttribArray(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 "glDisableVertexAttribArrayARB(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 enabled, now being disabled */
708 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
709 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
710 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
711 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
717 * Return info for a vertex attribute array (no alias with legacy
718 * vertex attributes (pos, normal, color, etc)). This function does
719 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
722 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
725 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
726 const struct gl_vertex_attrib_array
*array
;
728 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
729 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
733 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(vao
->VertexAttrib
));
735 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
738 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
739 return array
->Enabled
;
740 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
741 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
742 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
743 return array
->Stride
;
744 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
746 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
747 return array
->Normalized
;
748 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
749 return vao
->VertexBinding
[array
->VertexBinding
].BufferObj
->Name
;
750 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
751 if ((_mesa_is_desktop_gl(ctx
)
752 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
753 || _mesa_is_gles3(ctx
)) {
754 return array
->Integer
;
757 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
758 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
759 || _mesa_is_gles3(ctx
)) {
760 return vao
->VertexBinding
[array
->VertexBinding
].InstanceDivisor
;
763 case GL_VERTEX_ATTRIB_BINDING
:
764 if (_mesa_is_desktop_gl(ctx
)) {
765 return array
->VertexBinding
- VERT_ATTRIB_GENERIC0
;
768 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
769 if (_mesa_is_desktop_gl(ctx
)) {
770 return array
->RelativeOffset
;
778 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
783 static const GLfloat
*
784 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
787 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
788 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
792 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
793 _mesa_error(ctx
, GL_INVALID_VALUE
,
794 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
798 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.VAO
->_VertexAttrib
));
800 FLUSH_CURRENT(ctx
, 0);
801 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
805 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
807 GET_CURRENT_CONTEXT(ctx
);
809 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
810 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
816 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
817 "glGetVertexAttribfv");
823 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
825 GET_CURRENT_CONTEXT(ctx
);
827 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
828 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
830 params
[0] = (GLdouble
) v
[0];
831 params
[1] = (GLdouble
) v
[1];
832 params
[2] = (GLdouble
) v
[2];
833 params
[3] = (GLdouble
) v
[3];
837 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
838 "glGetVertexAttribdv");
844 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
846 GET_CURRENT_CONTEXT(ctx
);
848 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
849 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
851 /* XXX should floats in[0,1] be scaled to full int range? */
852 params
[0] = (GLint
) v
[0];
853 params
[1] = (GLint
) v
[1];
854 params
[2] = (GLint
) v
[2];
855 params
[3] = (GLint
) v
[3];
859 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
860 "glGetVertexAttribiv");
867 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
869 GET_CURRENT_CONTEXT(ctx
);
871 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
872 const GLint
*v
= (const GLint
*)
873 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
879 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
880 "glGetVertexAttribIiv");
887 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
889 GET_CURRENT_CONTEXT(ctx
);
891 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
892 const GLuint
*v
= (const GLuint
*)
893 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
899 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
900 "glGetVertexAttribIuiv");
906 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
908 GET_CURRENT_CONTEXT(ctx
);
910 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
911 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
915 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
916 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
920 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.VAO
->_VertexAttrib
));
922 *pointer
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
927 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
928 GLsizei count
, const GLvoid
*ptr
)
931 _mesa_VertexPointer(size
, type
, stride
, ptr
);
936 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
940 _mesa_NormalPointer(type
, stride
, ptr
);
945 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
949 _mesa_ColorPointer(size
, type
, stride
, ptr
);
954 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
958 _mesa_IndexPointer(type
, stride
, ptr
);
963 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
964 GLsizei count
, const GLvoid
*ptr
)
967 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
972 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
975 _mesa_EdgeFlagPointer(stride
, ptr
);
980 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
982 GET_CURRENT_CONTEXT(ctx
);
983 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
984 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
985 GLenum ctype
= 0; /* color type */
986 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
987 const GLint toffset
= 0; /* always zero */
988 GLint defstride
; /* default stride */
991 FLUSH_VERTICES(ctx
, 0);
994 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
997 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1003 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1004 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1009 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1010 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1015 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1016 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1017 ctype
= GL_UNSIGNED_BYTE
;
1020 defstride
= c
+ 2*f
;
1023 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1024 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1025 ctype
= GL_UNSIGNED_BYTE
;
1028 defstride
= c
+ 3*f
;
1031 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1032 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1039 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1040 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1045 case GL_C4F_N3F_V3F
:
1046 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1047 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1055 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1056 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1061 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1062 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1066 case GL_T2F_C4UB_V3F
:
1067 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1068 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1069 ctype
= GL_UNSIGNED_BYTE
;
1074 case GL_T2F_C3F_V3F
:
1075 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1076 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1082 case GL_T2F_N3F_V3F
:
1083 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1084 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1089 case GL_T2F_C4F_N3F_V3F
:
1090 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1091 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1098 case GL_T4F_C4F_N3F_V4F
:
1099 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1100 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1108 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1116 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1117 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1118 /* XXX also disable secondary color and generic arrays? */
1122 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1123 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1124 (GLubyte
*) pointer
+ toffset
);
1127 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1132 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1133 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1134 (GLubyte
*) pointer
+ coffset
);
1137 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1143 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1144 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1147 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1151 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1152 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1153 (GLubyte
*) pointer
+ voffset
);
1158 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1160 GET_CURRENT_CONTEXT(ctx
);
1162 FLUSH_VERTICES(ctx
, 0);
1164 if (MESA_VERBOSE
& VERBOSE_API
)
1165 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1168 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1172 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1175 if (ctx
->Array
.LockCount
!= 0) {
1176 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1180 ctx
->Array
.LockFirst
= first
;
1181 ctx
->Array
.LockCount
= count
;
1183 ctx
->NewState
|= _NEW_ARRAY
;
1188 _mesa_UnlockArraysEXT( void )
1190 GET_CURRENT_CONTEXT(ctx
);
1192 FLUSH_VERTICES(ctx
, 0);
1194 if (MESA_VERBOSE
& VERBOSE_API
)
1195 _mesa_debug(ctx
, "glUnlockArrays\n");
1197 if (ctx
->Array
.LockCount
== 0) {
1198 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1202 ctx
->Array
.LockFirst
= 0;
1203 ctx
->Array
.LockCount
= 0;
1204 ctx
->NewState
|= _NEW_ARRAY
;
1208 /* GL_EXT_multi_draw_arrays */
1210 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1211 const GLsizei
*count
, GLsizei primcount
)
1213 GET_CURRENT_CONTEXT(ctx
);
1216 FLUSH_VERTICES(ctx
, 0);
1218 for (i
= 0; i
< primcount
; i
++) {
1220 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1226 /* GL_IBM_multimode_draw_arrays */
1228 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1229 const GLsizei
* count
,
1230 GLsizei primcount
, GLint modestride
)
1232 GET_CURRENT_CONTEXT(ctx
);
1235 FLUSH_VERTICES(ctx
, 0);
1237 for ( i
= 0 ; i
< primcount
; i
++ ) {
1238 if ( count
[i
] > 0 ) {
1239 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1240 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1246 /* GL_IBM_multimode_draw_arrays */
1248 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1249 GLenum type
, const GLvoid
* const * indices
,
1250 GLsizei primcount
, GLint modestride
)
1252 GET_CURRENT_CONTEXT(ctx
);
1255 FLUSH_VERTICES(ctx
, 0);
1257 /* XXX not sure about ARB_vertex_buffer_object handling here */
1259 for ( i
= 0 ; i
< primcount
; i
++ ) {
1260 if ( count
[i
] > 0 ) {
1261 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1262 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1270 * GL_NV_primitive_restart and GL 3.1
1273 _mesa_PrimitiveRestartIndex(GLuint index
)
1275 GET_CURRENT_CONTEXT(ctx
);
1277 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1278 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1282 if (ctx
->Array
.RestartIndex
!= index
) {
1283 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1284 ctx
->Array
.RestartIndex
= index
;
1290 * See GL_ARB_instanced_arrays.
1291 * Note that the instance divisor only applies to generic arrays, not
1292 * the legacy vertex arrays.
1295 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1297 GET_CURRENT_CONTEXT(ctx
);
1299 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1301 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1302 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1306 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1307 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1312 ASSERT(genericIndex
< Elements(ctx
->Array
.VAO
->VertexAttrib
));
1314 /* The ARB_vertex_attrib_binding spec says:
1318 * void VertexAttribDivisor(uint index, uint divisor);
1320 * is equivalent to (assuming no errors are generated):
1322 * VertexAttribBinding(index, index);
1323 * VertexBindingDivisor(index, divisor);"
1325 vertex_attrib_binding(ctx
, genericIndex
, genericIndex
);
1326 vertex_binding_divisor(ctx
, genericIndex
, divisor
);
1331 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1333 /* From the OpenGL 4.3 core specification, page 302:
1334 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1335 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1338 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1340 case GL_UNSIGNED_BYTE
:
1342 case GL_UNSIGNED_SHORT
:
1344 case GL_UNSIGNED_INT
:
1347 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1351 return ctx
->Array
.RestartIndex
;
1356 * GL_ARB_vertex_attrib_binding
1359 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1362 GET_CURRENT_CONTEXT(ctx
);
1363 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1364 struct gl_buffer_object
*vbo
;
1366 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1368 /* The ARB_vertex_attrib_binding spec says:
1370 * "An INVALID_OPERATION error is generated if no vertex array object
1373 if (ctx
->API
== API_OPENGL_CORE
&&
1374 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1375 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1376 "glBindVertexBuffer(No array object bound)");
1380 /* The ARB_vertex_attrib_binding spec says:
1382 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1383 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1385 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1386 _mesa_error(ctx
, GL_INVALID_VALUE
,
1387 "glBindVertexBuffer(bindingindex=%u > "
1388 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1393 /* The ARB_vertex_attrib_binding spec says:
1395 * "The error INVALID_VALUE is generated if <stride> or <offset>
1399 _mesa_error(ctx
, GL_INVALID_VALUE
,
1400 "glBindVertexBuffer(offset=%lld < 0)", (long long)offset
);
1405 _mesa_error(ctx
, GL_INVALID_VALUE
,
1406 "glBindVertexBuffer(stride=%d < 0)", stride
);
1410 if (buffer
== vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1411 vbo
= vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1412 } else if (buffer
!= 0) {
1413 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1415 /* From the GL_ARB_vertex_attrib_array spec:
1417 * "[Core profile only:]
1418 * An INVALID_OPERATION error is generated if buffer is not zero or a
1419 * name returned from a previous call to GenBuffers, or if such a name
1420 * has since been deleted with DeleteBuffers.
1422 * Otherwise, we fall back to the same compat profile behavior as other
1423 * object references (automatically gen it).
1425 if (!_mesa_handle_bind_buffer_gen(ctx
, GL_ARRAY_BUFFER
, buffer
,
1426 &vbo
, "glBindVertexBuffer"))
1429 /* The ARB_vertex_attrib_binding spec says:
1431 * "If <buffer> is zero, any buffer object attached to this
1432 * bindpoint is detached."
1434 vbo
= ctx
->Shared
->NullBufferObj
;
1437 bind_vertex_buffer(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
),
1438 vbo
, offset
, stride
);
1443 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1444 const GLintptr
*offsets
, const GLsizei
*strides
)
1450 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1451 GLboolean normalized
, GLuint relativeOffset
)
1453 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1454 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1455 INT_BIT
| UNSIGNED_INT_BIT
|
1456 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1458 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1459 INT_2_10_10_10_REV_BIT
|
1460 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1462 GET_CURRENT_CONTEXT(ctx
);
1463 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1465 /* The ARB_vertex_attrib_binding spec says:
1467 * "An INVALID_OPERATION error is generated under any of the following
1469 * - if no vertex array object is currently bound (see section 2.10);
1472 if (ctx
->API
== API_OPENGL_CORE
&&
1473 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1474 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1475 "glVertexAttribFormat(No array object bound)");
1479 /* The ARB_vertex_attrib_binding spec says:
1481 * "The error INVALID_VALUE is generated if index is greater than or equal
1482 * to the value of MAX_VERTEX_ATTRIBS."
1484 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1485 _mesa_error(ctx
, GL_INVALID_VALUE
,
1486 "glVertexAttribFormat(attribindex=%u > "
1487 "GL_MAX_VERTEX_ATTRIBS)",
1492 FLUSH_VERTICES(ctx
, 0);
1494 update_array_format(ctx
, "glVertexAttribFormat",
1495 VERT_ATTRIB_GENERIC(attribIndex
),
1496 legalTypes
, 1, BGRA_OR_4
, size
, type
, normalized
,
1497 GL_FALSE
, relativeOffset
);
1502 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1503 GLuint relativeOffset
)
1505 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1506 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1507 INT_BIT
| UNSIGNED_INT_BIT
);
1509 GET_CURRENT_CONTEXT(ctx
);
1510 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1512 /* The ARB_vertex_attrib_binding spec says:
1514 * "An INVALID_OPERATION error is generated under any of the following
1516 * - if no vertex array object is currently bound (see section 2.10);
1519 if (ctx
->API
== API_OPENGL_CORE
&&
1520 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1521 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1522 "glVertexAttribIFormat(No array object bound)");
1526 /* The ARB_vertex_attrib_binding spec says:
1528 * "The error INVALID_VALUE is generated if index is greater than
1529 * or equal to the value of MAX_VERTEX_ATTRIBS."
1531 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1532 _mesa_error(ctx
, GL_INVALID_VALUE
,
1533 "glVertexAttribIFormat(attribindex=%u > "
1534 "GL_MAX_VERTEX_ATTRIBS)",
1539 FLUSH_VERTICES(ctx
, 0);
1541 update_array_format(ctx
, "glVertexAttribIFormat",
1542 VERT_ATTRIB_GENERIC(attribIndex
),
1543 legalTypes
, 1, 4, size
, type
, GL_FALSE
, GL_TRUE
,
1549 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1550 GLuint relativeOffset
)
1552 const GLbitfield legalTypes
= DOUBLE_BIT
;
1554 GET_CURRENT_CONTEXT(ctx
);
1555 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1557 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
1559 * "An INVALID_OPERATION error is generated under any of the following
1561 * • if no vertex array object is currently bound (see section 10.4);
1564 * This language is missing from the extension spec, but we assume
1565 * that this is an oversight.
1567 if (ctx
->API
== API_OPENGL_CORE
&&
1568 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1569 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1570 "glVertexAttribLFormat(No array object bound)");
1574 /* The ARB_vertex_attrib_binding spec says:
1576 * "The error INVALID_VALUE is generated if <attribindex> is greater than
1577 * or equal to the value of MAX_VERTEX_ATTRIBS."
1579 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1580 _mesa_error(ctx
, GL_INVALID_VALUE
,
1581 "glVertexAttribLFormat(attribindex=%u > "
1582 "GL_MAX_VERTEX_ATTRIBS)",
1587 FLUSH_VERTICES(ctx
, 0);
1589 update_array_format(ctx
, "glVertexAttribLFormat",
1590 VERT_ATTRIB_GENERIC(attribIndex
),
1591 legalTypes
, 1, 4, size
, type
, GL_FALSE
, GL_FALSE
,
1597 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
1599 GET_CURRENT_CONTEXT(ctx
);
1600 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1602 /* The ARB_vertex_attrib_binding spec says:
1604 * "An INVALID_OPERATION error is generated if no vertex array object
1607 if (ctx
->API
== API_OPENGL_CORE
&&
1608 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1609 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1610 "glVertexAttribBinding(No array object bound)");
1614 /* The ARB_vertex_attrib_binding spec says:
1616 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1617 * <bindingindex> must be less than the value of
1618 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1621 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1622 _mesa_error(ctx
, GL_INVALID_VALUE
,
1623 "glVertexAttribBinding(attribindex=%u >= "
1624 "GL_MAX_VERTEX_ATTRIBS)",
1629 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1630 _mesa_error(ctx
, GL_INVALID_VALUE
,
1631 "glVertexAttribBinding(bindingindex=%u >= "
1632 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1637 ASSERT(VERT_ATTRIB_GENERIC(attribIndex
) <
1638 Elements(ctx
->Array
.VAO
->VertexAttrib
));
1640 vertex_attrib_binding(ctx
, VERT_ATTRIB_GENERIC(attribIndex
),
1641 VERT_ATTRIB_GENERIC(bindingIndex
));
1646 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
1648 GET_CURRENT_CONTEXT(ctx
);
1649 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1651 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1652 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexBindingDivisor()");
1656 /* The ARB_vertex_attrib_binding spec says:
1658 * "An INVALID_OPERATION error is generated if no vertex array object
1661 if (ctx
->API
== API_OPENGL_CORE
&&
1662 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1663 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1664 "glVertexBindingDivisor(No array object bound)");
1668 /* The ARB_vertex_attrib_binding spec says:
1670 * "An INVALID_VALUE error is generated if <bindingindex> is greater
1671 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
1673 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1674 _mesa_error(ctx
, GL_INVALID_VALUE
,
1675 "glVertexBindingDivisor(bindingindex=%u > "
1676 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1681 vertex_binding_divisor(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
1686 * Copy one client vertex array to another.
1689 _mesa_copy_client_array(struct gl_context
*ctx
,
1690 struct gl_client_array
*dst
,
1691 struct gl_client_array
*src
)
1693 dst
->Size
= src
->Size
;
1694 dst
->Type
= src
->Type
;
1695 dst
->Format
= src
->Format
;
1696 dst
->Stride
= src
->Stride
;
1697 dst
->StrideB
= src
->StrideB
;
1698 dst
->Ptr
= src
->Ptr
;
1699 dst
->Enabled
= src
->Enabled
;
1700 dst
->Normalized
= src
->Normalized
;
1701 dst
->Integer
= src
->Integer
;
1702 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1703 dst
->_ElementSize
= src
->_ElementSize
;
1704 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1705 dst
->_MaxElement
= src
->_MaxElement
;
1709 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
1710 struct gl_vertex_attrib_array
*dst
,
1711 const struct gl_vertex_attrib_array
*src
)
1713 dst
->Size
= src
->Size
;
1714 dst
->Type
= src
->Type
;
1715 dst
->Format
= src
->Format
;
1716 dst
->VertexBinding
= src
->VertexBinding
;
1717 dst
->RelativeOffset
= src
->RelativeOffset
;
1718 dst
->Format
= src
->Format
;
1719 dst
->Integer
= src
->Integer
;
1720 dst
->Normalized
= src
->Normalized
;
1721 dst
->Ptr
= src
->Ptr
;
1722 dst
->Enabled
= src
->Enabled
;
1723 dst
->_ElementSize
= src
->_ElementSize
;
1727 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
1728 struct gl_vertex_buffer_binding
*dst
,
1729 const struct gl_vertex_buffer_binding
*src
)
1731 dst
->Offset
= src
->Offset
;
1732 dst
->Stride
= src
->Stride
;
1733 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1734 dst
->_BoundArrays
= src
->_BoundArrays
;
1736 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1740 * Print vertex array's fields.
1743 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1746 printf(" %s[%d]: ", name
, index
);
1748 printf(" %s: ", name
);
1749 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
1750 array
->Ptr
, array
->Type
, array
->Size
,
1751 array
->_ElementSize
, array
->StrideB
,
1752 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
,
1753 array
->_MaxElement
);
1758 * Print current vertex object/array info. For debug.
1761 _mesa_print_arrays(struct gl_context
*ctx
)
1763 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1766 _mesa_update_vao_max_element(ctx
, vao
);
1768 printf("Array Object %u\n", vao
->Name
);
1769 if (vao
->_VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
1770 print_array("Vertex", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_POS
]);
1771 if (vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
1772 print_array("Normal", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
]);
1773 if (vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
1774 print_array("Color", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
]);
1775 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
1776 if (vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
1777 print_array("TexCoord", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
1778 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
1779 if (vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
1780 print_array("Attrib", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
1781 printf(" _MaxElement = %u\n", vao
->_MaxElement
);
1786 * Initialize vertex array state for given context.
1789 _mesa_init_varray(struct gl_context
*ctx
)
1791 ctx
->Array
.DefaultVAO
= ctx
->Driver
.NewArrayObject(ctx
, 0);
1792 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
1793 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1795 ctx
->Array
.Objects
= _mesa_NewHashTable();
1800 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1803 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1805 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
1806 struct gl_context
*ctx
= (struct gl_context
*) userData
;
1807 _mesa_delete_vao(ctx
, vao
);
1812 * Free vertex array state for given context.
1815 _mesa_free_varray_data(struct gl_context
*ctx
)
1817 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1818 _mesa_DeleteHashTable(ctx
->Array
.Objects
);