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
65 /** Convert GL datatype enum into a <type>_BIT value seen above */
67 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
74 case GL_UNSIGNED_BYTE
:
75 return UNSIGNED_BYTE_BIT
;
78 case GL_UNSIGNED_SHORT
:
79 return UNSIGNED_SHORT_BIT
;
83 return UNSIGNED_INT_BIT
;
85 if (ctx
->Extensions
.ARB_half_float_vertex
)
94 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
95 case GL_UNSIGNED_INT_2_10_10_10_REV
:
96 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
97 case GL_INT_2_10_10_10_REV
:
98 return INT_2_10_10_10_REV_BIT
;
106 * Sets the VertexBinding field in the vertex attribute given by attribIndex.
109 vertex_attrib_binding(struct gl_context
*ctx
, GLuint attribIndex
,
112 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
113 struct gl_vertex_attrib_array
*array
= &arrayObj
->VertexAttrib
[attribIndex
];
115 if (array
->VertexBinding
!= bindingIndex
) {
116 const GLbitfield64 array_bit
= VERT_BIT(attribIndex
);
118 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
120 arrayObj
->VertexBinding
[array
->VertexBinding
]._BoundArrays
&= ~array_bit
;
121 arrayObj
->VertexBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
123 array
->VertexBinding
= bindingIndex
;
125 arrayObj
->NewArrays
|= array_bit
;
131 * Binds a buffer object to the vertex buffer binding point given by index,
132 * and sets the Offset and Stride fields.
135 bind_vertex_buffer(struct gl_context
*ctx
, GLuint index
,
136 struct gl_buffer_object
*vbo
,
137 GLintptr offset
, GLsizei stride
)
139 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
140 struct gl_vertex_buffer_binding
*binding
= &arrayObj
->VertexBinding
[index
];
142 if (binding
->BufferObj
!= vbo
||
143 binding
->Offset
!= offset
||
144 binding
->Stride
!= stride
) {
146 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
148 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
150 binding
->Offset
= offset
;
151 binding
->Stride
= stride
;
153 arrayObj
->NewArrays
|= binding
->_BoundArrays
;
159 * Sets the InstanceDivisor field in the vertex buffer binding point
160 * given by bindingIndex.
163 vertex_binding_divisor(struct gl_context
*ctx
, GLuint bindingIndex
,
166 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
167 struct gl_vertex_buffer_binding
*binding
=
168 &arrayObj
->VertexBinding
[bindingIndex
];
170 if (binding
->InstanceDivisor
!= divisor
) {
171 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
172 binding
->InstanceDivisor
= divisor
;
173 arrayObj
->NewArrays
|= binding
->_BoundArrays
;
179 * Does error checking and updates the format in an attrib array.
181 * Called by update_array() and VertexAttrib*Format().
183 * \param func Name of calling function used for error reporting
184 * \param attrib The index of the attribute array
185 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
186 * \param sizeMin Min allowable size value
187 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
188 * \param size Components per element (1, 2, 3 or 4)
189 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
190 * \param normalized Whether integer types are converted to floats in [-1, 1]
191 * \param integer Integer-valued values (will not be normalized to [-1, 1])
192 * \param relativeOffset Offset of the first element relative to the binding offset.
195 update_array_format(struct gl_context
*ctx
,
197 GLuint attrib
, GLbitfield legalTypesMask
,
198 GLint sizeMin
, GLint sizeMax
,
199 GLint size
, GLenum type
,
200 GLboolean normalized
, GLboolean integer
,
201 GLuint relativeOffset
)
203 struct gl_vertex_attrib_array
*array
;
206 GLenum format
= GL_RGBA
;
208 if (_mesa_is_gles(ctx
)) {
209 legalTypesMask
&= ~(FIXED_GL_BIT
| DOUBLE_BIT
);
211 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
212 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
213 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
214 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
215 * quite as trivial as we'd like because it uses a different enum value
216 * for GL_HALF_FLOAT_OES.
218 if (ctx
->Version
< 30) {
219 legalTypesMask
&= ~(UNSIGNED_INT_BIT
221 | UNSIGNED_INT_2_10_10_10_REV_BIT
222 | INT_2_10_10_10_REV_BIT
226 /* BGRA ordering is not supported in ES contexts.
228 if (sizeMax
== BGRA_OR_4
)
231 legalTypesMask
&= ~FIXED_ES_BIT
;
233 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
234 legalTypesMask
&= ~FIXED_GL_BIT
;
236 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
237 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
238 INT_2_10_10_10_REV_BIT
);
241 typeBit
= type_to_bit(ctx
, type
);
242 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
243 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
244 func
, _mesa_lookup_enum_by_nr(type
));
248 /* Do size parameter checking.
249 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
250 * must be handled specially.
252 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
253 sizeMax
== BGRA_OR_4
&&
255 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
257 * "An INVALID_OPERATION error is generated under any of the following
260 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
261 * or UNSIGNED_INT_2_10_10_10_REV;
263 * • size is BGRA and normalized is FALSE;"
265 bool bgra_error
= false;
267 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
268 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
269 type
!= GL_INT_2_10_10_10_REV
&&
270 type
!= GL_UNSIGNED_BYTE
)
272 } else if (type
!= GL_UNSIGNED_BYTE
)
276 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
277 func
, _mesa_lookup_enum_by_nr(type
));
282 _mesa_error(ctx
, GL_INVALID_OPERATION
,
283 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
290 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
291 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
295 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
296 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
297 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
298 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
302 /* The ARB_vertex_attrib_binding_spec says:
304 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
305 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
307 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
308 _mesa_error(ctx
, GL_INVALID_VALUE
,
309 "%s(relativeOffset=%d > "
310 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
311 func
, relativeOffset
);
317 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
318 assert(elementSize
!= -1);
320 array
= &ctx
->Array
.ArrayObj
->VertexAttrib
[attrib
];
323 array
->Format
= format
;
324 array
->Normalized
= normalized
;
325 array
->Integer
= integer
;
326 array
->RelativeOffset
= relativeOffset
;
327 array
->_ElementSize
= elementSize
;
329 ctx
->Array
.ArrayObj
->NewArrays
|= VERT_BIT(attrib
);
330 ctx
->NewState
|= _NEW_ARRAY
;
337 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
340 * \param func name of calling function used for error reporting
341 * \param attrib the attribute array index to update
342 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
343 * \param sizeMin min allowable size value
344 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
345 * \param size components per element (1, 2, 3 or 4)
346 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
347 * \param stride stride between elements, in elements
348 * \param normalized are integer types converted to floats in [-1, 1]?
349 * \param integer integer-valued values (will not be normalized to [-1,1])
350 * \param ptr the address (or offset inside VBO) of the array data
353 update_array(struct gl_context
*ctx
,
355 GLuint attrib
, GLbitfield legalTypesMask
,
356 GLint sizeMin
, GLint sizeMax
,
357 GLint size
, GLenum type
, GLsizei stride
,
358 GLboolean normalized
, GLboolean integer
,
361 struct gl_vertex_attrib_array
*array
;
362 GLsizei effectiveStride
;
364 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
366 * "Client vertex arrays - all vertex array attribute pointers must
367 * refer to buffer objects (section 2.9.2). The default vertex array
368 * object (the name zero) is also deprecated. Calling
369 * VertexAttribPointer when no buffer object or no vertex array object
370 * is bound will generate an INVALID_OPERATION error..."
372 * The check for VBOs is handled below.
374 if (ctx
->API
== API_OPENGL_CORE
375 && (ctx
->Array
.ArrayObj
== ctx
->Array
.DefaultArrayObj
)) {
376 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
381 if (!update_array_format(ctx
, func
, attrib
, legalTypesMask
, sizeMin
, sizeMax
,
382 size
, type
, normalized
, integer
, 0)) {
387 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
391 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
393 * "An INVALID_OPERATION error is generated under any of the following
398 * * any of the *Pointer commands specifying the location and
399 * organization of vertex array data are called while zero is bound
400 * to the ARRAY_BUFFER buffer object binding point (see section
401 * 2.9.6), and the pointer argument is not NULL."
403 if (ptr
!= NULL
&& ctx
->Array
.ArrayObj
->ARBsemantics
&&
404 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
405 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
409 /* Reset the vertex attrib binding */
410 vertex_attrib_binding(ctx
, attrib
, attrib
);
412 /* The Stride and Ptr fields are not set by update_array_format() */
413 array
= &ctx
->Array
.ArrayObj
->VertexAttrib
[attrib
];
414 array
->Stride
= stride
;
415 array
->Ptr
= (const GLvoid
*) ptr
;
417 /* Update the vertex buffer binding */
418 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
419 bind_vertex_buffer(ctx
, attrib
, ctx
->Array
.ArrayBufferObj
,
420 (GLintptr
) ptr
, effectiveStride
);
425 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
427 GET_CURRENT_CONTEXT(ctx
);
428 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
429 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
430 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
431 DOUBLE_BIT
| HALF_BIT
|
432 UNSIGNED_INT_2_10_10_10_REV_BIT
|
433 INT_2_10_10_10_REV_BIT
);
435 FLUSH_VERTICES(ctx
, 0);
437 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
439 size
, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
444 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
446 GET_CURRENT_CONTEXT(ctx
);
447 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
448 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
449 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
450 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
451 UNSIGNED_INT_2_10_10_10_REV_BIT
|
452 INT_2_10_10_10_REV_BIT
);
454 FLUSH_VERTICES(ctx
, 0);
456 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
458 3, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
463 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
465 GET_CURRENT_CONTEXT(ctx
);
466 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
467 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
468 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
469 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
470 INT_BIT
| UNSIGNED_INT_BIT
|
471 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
472 UNSIGNED_INT_2_10_10_10_REV_BIT
|
473 INT_2_10_10_10_REV_BIT
);
474 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
476 FLUSH_VERTICES(ctx
, 0);
478 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
479 legalTypes
, sizeMin
, BGRA_OR_4
,
480 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
485 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
487 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
488 GET_CURRENT_CONTEXT(ctx
);
490 FLUSH_VERTICES(ctx
, 0);
492 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
494 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
499 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
501 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
502 FLOAT_BIT
| DOUBLE_BIT
);
503 GET_CURRENT_CONTEXT(ctx
);
505 FLUSH_VERTICES(ctx
, 0);
507 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
509 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
514 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
515 GLsizei stride
, const GLvoid
*ptr
)
517 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
518 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
519 INT_BIT
| UNSIGNED_INT_BIT
|
520 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
521 UNSIGNED_INT_2_10_10_10_REV_BIT
|
522 INT_2_10_10_10_REV_BIT
);
523 GET_CURRENT_CONTEXT(ctx
);
525 FLUSH_VERTICES(ctx
, 0);
527 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
528 legalTypes
, 3, BGRA_OR_4
,
529 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
534 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
537 GET_CURRENT_CONTEXT(ctx
);
538 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
539 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
540 : (SHORT_BIT
| INT_BIT
|
541 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
542 UNSIGNED_INT_2_10_10_10_REV_BIT
|
543 INT_2_10_10_10_REV_BIT
);
544 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
545 const GLuint unit
= ctx
->Array
.ActiveTexture
;
547 FLUSH_VERTICES(ctx
, 0);
549 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
550 legalTypes
, sizeMin
, 4,
551 size
, type
, stride
, GL_FALSE
, GL_FALSE
,
557 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
559 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
560 /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
561 const GLboolean integer
= GL_TRUE
;
562 GET_CURRENT_CONTEXT(ctx
);
564 FLUSH_VERTICES(ctx
, 0);
566 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
568 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, ptr
);
573 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
575 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
576 GET_CURRENT_CONTEXT(ctx
);
578 FLUSH_VERTICES(ctx
, 0);
580 if (ctx
->API
!= API_OPENGLES
) {
581 _mesa_error(ctx
, GL_INVALID_OPERATION
,
582 "glPointSizePointer(ES 1.x only)");
586 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
588 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
593 * Set a generic vertex attribute array.
594 * Note that these arrays DO NOT alias the conventional GL vertex arrays
595 * (position, normal, color, fog, texcoord, etc).
598 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
599 GLboolean normalized
,
600 GLsizei stride
, const GLvoid
*ptr
)
602 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
603 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
604 INT_BIT
| UNSIGNED_INT_BIT
|
605 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
606 FIXED_ES_BIT
| FIXED_GL_BIT
|
607 UNSIGNED_INT_2_10_10_10_REV_BIT
|
608 INT_2_10_10_10_REV_BIT
);
609 GET_CURRENT_CONTEXT(ctx
);
611 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
612 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
616 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
617 legalTypes
, 1, BGRA_OR_4
,
618 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
623 * GL_EXT_gpu_shader4 / GL 3.0.
624 * Set an integer-valued vertex attribute array.
625 * Note that these arrays DO NOT alias the conventional GL vertex arrays
626 * (position, normal, color, fog, texcoord, etc).
629 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
630 GLsizei stride
, const GLvoid
*ptr
)
632 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
633 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
634 INT_BIT
| UNSIGNED_INT_BIT
);
635 const GLboolean normalized
= GL_FALSE
;
636 const GLboolean integer
= GL_TRUE
;
637 GET_CURRENT_CONTEXT(ctx
);
639 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
640 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
644 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
646 size
, type
, stride
, normalized
, integer
, ptr
);
652 _mesa_EnableVertexAttribArray(GLuint index
)
654 struct gl_array_object
*arrayObj
;
655 GET_CURRENT_CONTEXT(ctx
);
657 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
658 _mesa_error(ctx
, GL_INVALID_VALUE
,
659 "glEnableVertexAttribArrayARB(index)");
663 arrayObj
= ctx
->Array
.ArrayObj
;
665 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(arrayObj
->_VertexAttrib
));
667 if (!arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
668 /* was disabled, now being enabled */
669 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
670 arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
671 arrayObj
->_Enabled
|= VERT_BIT_GENERIC(index
);
672 arrayObj
->NewArrays
|= VERT_BIT_GENERIC(index
);
678 _mesa_DisableVertexAttribArray(GLuint index
)
680 struct gl_array_object
*arrayObj
;
681 GET_CURRENT_CONTEXT(ctx
);
683 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
684 _mesa_error(ctx
, GL_INVALID_VALUE
,
685 "glDisableVertexAttribArrayARB(index)");
689 arrayObj
= ctx
->Array
.ArrayObj
;
691 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(arrayObj
->_VertexAttrib
));
693 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
694 /* was enabled, now being disabled */
695 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
696 arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
697 arrayObj
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
698 arrayObj
->NewArrays
|= VERT_BIT_GENERIC(index
);
704 * Return info for a vertex attribute array (no alias with legacy
705 * vertex attributes (pos, normal, color, etc)). This function does
706 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
709 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
712 const struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
713 const struct gl_vertex_attrib_array
*array
;
715 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
716 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
720 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(arrayObj
->VertexAttrib
));
722 array
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
725 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
726 return array
->Enabled
;
727 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
729 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
730 return array
->Stride
;
731 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
733 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
734 return array
->Normalized
;
735 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
736 return arrayObj
->VertexBinding
[array
->VertexBinding
].BufferObj
->Name
;
737 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
738 if ((_mesa_is_desktop_gl(ctx
)
739 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
740 || _mesa_is_gles3(ctx
)) {
741 return array
->Integer
;
744 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
745 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
746 || _mesa_is_gles3(ctx
)) {
747 return arrayObj
->VertexBinding
[array
->VertexBinding
].InstanceDivisor
;
750 case GL_VERTEX_ATTRIB_BINDING
:
751 if (_mesa_is_desktop_gl(ctx
)) {
752 return array
->VertexBinding
- VERT_ATTRIB_GENERIC0
;
755 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
756 if (_mesa_is_desktop_gl(ctx
)) {
757 return array
->RelativeOffset
;
765 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
770 static const GLfloat
*
771 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
774 /* In OpenGL 3.1 attribute 0 becomes non-magic, just like in OpenGL ES
775 * 2.0. Note that we cannot just check for API_OPENGL_CORE here because
776 * that will erroneously allow this usage in a 3.0 forward-compatible
779 if ((ctx
->API
!= API_OPENGL_CORE
|| ctx
->Version
< 31)
780 && ctx
->API
!= API_OPENGLES2
) {
781 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
785 else if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
786 _mesa_error(ctx
, GL_INVALID_VALUE
,
787 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
791 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->_VertexAttrib
));
793 FLUSH_CURRENT(ctx
, 0);
794 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
798 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
800 GET_CURRENT_CONTEXT(ctx
);
802 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
803 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
809 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
810 "glGetVertexAttribfv");
816 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
818 GET_CURRENT_CONTEXT(ctx
);
820 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
821 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
823 params
[0] = (GLdouble
) v
[0];
824 params
[1] = (GLdouble
) v
[1];
825 params
[2] = (GLdouble
) v
[2];
826 params
[3] = (GLdouble
) v
[3];
830 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
831 "glGetVertexAttribdv");
837 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
839 GET_CURRENT_CONTEXT(ctx
);
841 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
842 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
844 /* XXX should floats in[0,1] be scaled to full int range? */
845 params
[0] = (GLint
) v
[0];
846 params
[1] = (GLint
) v
[1];
847 params
[2] = (GLint
) v
[2];
848 params
[3] = (GLint
) v
[3];
852 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
853 "glGetVertexAttribiv");
860 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
862 GET_CURRENT_CONTEXT(ctx
);
864 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
865 const GLint
*v
= (const GLint
*)
866 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
872 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
873 "glGetVertexAttribIiv");
880 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
882 GET_CURRENT_CONTEXT(ctx
);
884 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
885 const GLuint
*v
= (const GLuint
*)
886 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
892 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
893 "glGetVertexAttribIuiv");
899 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
901 GET_CURRENT_CONTEXT(ctx
);
903 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
904 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
908 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
909 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
913 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->_VertexAttrib
));
915 *pointer
= (GLvoid
*) ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
920 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
921 GLsizei count
, const GLvoid
*ptr
)
924 _mesa_VertexPointer(size
, type
, stride
, ptr
);
929 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
933 _mesa_NormalPointer(type
, stride
, ptr
);
938 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
942 _mesa_ColorPointer(size
, type
, stride
, ptr
);
947 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
951 _mesa_IndexPointer(type
, stride
, ptr
);
956 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
957 GLsizei count
, const GLvoid
*ptr
)
960 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
965 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
968 _mesa_EdgeFlagPointer(stride
, ptr
);
973 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
975 GET_CURRENT_CONTEXT(ctx
);
976 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
977 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
978 GLenum ctype
= 0; /* color type */
979 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
980 const GLint toffset
= 0; /* always zero */
981 GLint defstride
; /* default stride */
984 FLUSH_VERTICES(ctx
, 0);
987 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
990 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
996 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
997 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1002 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1003 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1008 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1009 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1010 ctype
= GL_UNSIGNED_BYTE
;
1013 defstride
= c
+ 2*f
;
1016 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1017 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1018 ctype
= GL_UNSIGNED_BYTE
;
1021 defstride
= c
+ 3*f
;
1024 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1025 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1032 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1033 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1038 case GL_C4F_N3F_V3F
:
1039 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1040 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1048 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1049 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1054 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1055 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1059 case GL_T2F_C4UB_V3F
:
1060 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1061 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1062 ctype
= GL_UNSIGNED_BYTE
;
1067 case GL_T2F_C3F_V3F
:
1068 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1069 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1075 case GL_T2F_N3F_V3F
:
1076 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1077 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1082 case GL_T2F_C4F_N3F_V3F
:
1083 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1084 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1091 case GL_T4F_C4F_N3F_V4F
:
1092 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1093 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1101 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1109 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1110 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1111 /* XXX also disable secondary color and generic arrays? */
1115 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1116 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1117 (GLubyte
*) pointer
+ toffset
);
1120 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1125 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1126 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1127 (GLubyte
*) pointer
+ coffset
);
1130 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1136 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1137 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1140 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1144 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1145 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1146 (GLubyte
*) pointer
+ voffset
);
1151 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1153 GET_CURRENT_CONTEXT(ctx
);
1155 FLUSH_VERTICES(ctx
, 0);
1157 if (MESA_VERBOSE
& VERBOSE_API
)
1158 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1161 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1165 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1168 if (ctx
->Array
.LockCount
!= 0) {
1169 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1173 ctx
->Array
.LockFirst
= first
;
1174 ctx
->Array
.LockCount
= count
;
1176 ctx
->NewState
|= _NEW_ARRAY
;
1181 _mesa_UnlockArraysEXT( void )
1183 GET_CURRENT_CONTEXT(ctx
);
1185 FLUSH_VERTICES(ctx
, 0);
1187 if (MESA_VERBOSE
& VERBOSE_API
)
1188 _mesa_debug(ctx
, "glUnlockArrays\n");
1190 if (ctx
->Array
.LockCount
== 0) {
1191 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1195 ctx
->Array
.LockFirst
= 0;
1196 ctx
->Array
.LockCount
= 0;
1197 ctx
->NewState
|= _NEW_ARRAY
;
1201 /* GL_EXT_multi_draw_arrays */
1203 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1204 const GLsizei
*count
, GLsizei primcount
)
1206 GET_CURRENT_CONTEXT(ctx
);
1209 FLUSH_VERTICES(ctx
, 0);
1211 for (i
= 0; i
< primcount
; i
++) {
1213 CALL_DrawArrays(ctx
->Exec
, (mode
, first
[i
], count
[i
]));
1219 /* GL_IBM_multimode_draw_arrays */
1221 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1222 const GLsizei
* count
,
1223 GLsizei primcount
, GLint modestride
)
1225 GET_CURRENT_CONTEXT(ctx
);
1228 FLUSH_VERTICES(ctx
, 0);
1230 for ( i
= 0 ; i
< primcount
; i
++ ) {
1231 if ( count
[i
] > 0 ) {
1232 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1233 CALL_DrawArrays(ctx
->Exec
, ( m
, first
[i
], count
[i
] ));
1239 /* GL_IBM_multimode_draw_arrays */
1241 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1242 GLenum type
, const GLvoid
* const * indices
,
1243 GLsizei primcount
, GLint modestride
)
1245 GET_CURRENT_CONTEXT(ctx
);
1248 FLUSH_VERTICES(ctx
, 0);
1250 /* XXX not sure about ARB_vertex_buffer_object handling here */
1252 for ( i
= 0 ; i
< primcount
; i
++ ) {
1253 if ( count
[i
] > 0 ) {
1254 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1255 CALL_DrawElements(ctx
->Exec
, ( m
, count
[i
], type
, indices
[i
] ));
1262 * GL_NV_primitive_restart and GL 3.1
1265 _mesa_PrimitiveRestartIndex(GLuint index
)
1267 GET_CURRENT_CONTEXT(ctx
);
1269 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1270 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1274 if (ctx
->Array
.RestartIndex
!= index
) {
1275 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1276 ctx
->Array
.RestartIndex
= index
;
1282 * See GL_ARB_instanced_arrays.
1283 * Note that the instance divisor only applies to generic arrays, not
1284 * the legacy vertex arrays.
1287 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1289 GET_CURRENT_CONTEXT(ctx
);
1291 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1293 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1294 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1298 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
1299 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1304 ASSERT(genericIndex
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
1306 /* The ARB_vertex_attrib_binding spec says:
1310 * void VertexAttribDivisor(uint index, uint divisor);
1312 * is equivalent to (assuming no errors are generated):
1314 * VertexAttribBinding(index, index);
1315 * VertexBindingDivisor(index, divisor);"
1317 vertex_attrib_binding(ctx
, genericIndex
, genericIndex
);
1318 vertex_binding_divisor(ctx
, genericIndex
, divisor
);
1323 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1325 /* From the OpenGL 4.3 core specification, page 302:
1326 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1327 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1330 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1332 case GL_UNSIGNED_BYTE
:
1334 case GL_UNSIGNED_SHORT
:
1336 case GL_UNSIGNED_INT
:
1339 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1343 return ctx
->Array
.RestartIndex
;
1348 * GL_ARB_vertex_attrib_binding
1351 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1354 GET_CURRENT_CONTEXT(ctx
);
1355 const struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
1356 struct gl_buffer_object
*vbo
;
1358 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1360 /* The ARB_vertex_attrib_binding spec says:
1362 * "An INVALID_OPERATION error is generated if no vertex array object
1365 if (ctx
->API
== API_OPENGL_CORE
&&
1366 ctx
->Array
.ArrayObj
== ctx
->Array
.DefaultArrayObj
) {
1367 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1368 "glBindVertexBuffer(No array object bound)");
1372 /* The ARB_vertex_attrib_binding spec says:
1374 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1375 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1377 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1378 _mesa_error(ctx
, GL_INVALID_VALUE
,
1379 "glBindVertexBuffer(bindingindex=%u > "
1380 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1385 /* The ARB_vertex_attrib_binding spec says:
1387 * "The error INVALID_VALUE is generated if <stride> or <offset>
1391 _mesa_error(ctx
, GL_INVALID_VALUE
,
1392 "glBindVertexBuffer(offset=%lld < 0)", (long long)offset
);
1397 _mesa_error(ctx
, GL_INVALID_VALUE
,
1398 "glBindVertexBuffer(stride=%d < 0)", stride
);
1402 if (buffer
== arrayObj
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1403 vbo
= arrayObj
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1404 } else if (buffer
!= 0) {
1405 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1407 /* From the GL_ARB_vertex_attrib_array spec:
1409 * "[Core profile only:]
1410 * An INVALID_OPERATION error is generated if buffer is not zero or a
1411 * name returned from a previous call to GenBuffers, or if such a name
1412 * has since been deleted with DeleteBuffers.
1414 * Otherwise, we fall back to the same compat profile behavior as other
1415 * object references (automatically gen it).
1417 if (!_mesa_handle_bind_buffer_gen(ctx
, GL_ARRAY_BUFFER
, buffer
,
1418 &vbo
, "glBindVertexBuffer"))
1421 /* The ARB_vertex_attrib_binding spec says:
1423 * "If <buffer> is zero, any buffer object attached to this
1424 * bindpoint is detached."
1426 vbo
= ctx
->Shared
->NullBufferObj
;
1429 bind_vertex_buffer(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
),
1430 vbo
, offset
, stride
);
1435 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1436 GLboolean normalized
, GLuint relativeOffset
)
1438 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1439 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1440 INT_BIT
| UNSIGNED_INT_BIT
|
1441 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1443 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1444 INT_2_10_10_10_REV_BIT
);
1446 GET_CURRENT_CONTEXT(ctx
);
1447 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1449 /* The ARB_vertex_attrib_binding spec says:
1451 * "An INVALID_OPERATION error is generated under any of the following
1453 * - if no vertex array object is currently bound (see section 2.10);
1456 if (ctx
->API
== API_OPENGL_CORE
&&
1457 ctx
->Array
.ArrayObj
== ctx
->Array
.DefaultArrayObj
) {
1458 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1459 "glVertexAttribFormat(No array object bound)");
1463 /* The ARB_vertex_attrib_binding spec says:
1465 * "The error INVALID_VALUE is generated if index is greater than or equal
1466 * to the value of MAX_VERTEX_ATTRIBS."
1468 if (attribIndex
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
1469 _mesa_error(ctx
, GL_INVALID_VALUE
,
1470 "glVertexAttribFormat(attribindex=%u > "
1471 "GL_MAX_VERTEX_ATTRIBS)",
1476 FLUSH_VERTICES(ctx
, 0);
1478 update_array_format(ctx
, "glVertexAttribFormat",
1479 VERT_ATTRIB_GENERIC(attribIndex
),
1480 legalTypes
, 1, BGRA_OR_4
, size
, type
, normalized
,
1481 GL_FALSE
, relativeOffset
);
1486 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1487 GLuint relativeOffset
)
1489 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1490 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1491 INT_BIT
| UNSIGNED_INT_BIT
);
1493 GET_CURRENT_CONTEXT(ctx
);
1494 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1496 /* The ARB_vertex_attrib_binding spec says:
1498 * "An INVALID_OPERATION error is generated under any of the following
1500 * - if no vertex array object is currently bound (see section 2.10);
1503 if (ctx
->API
== API_OPENGL_CORE
&&
1504 ctx
->Array
.ArrayObj
== ctx
->Array
.DefaultArrayObj
) {
1505 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1506 "glVertexAttribIFormat(No array object bound)");
1510 /* The ARB_vertex_attrib_binding spec says:
1512 * "The error INVALID_VALUE is generated if index is greater than
1513 * or equal to the value of MAX_VERTEX_ATTRIBS."
1515 if (attribIndex
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
1516 _mesa_error(ctx
, GL_INVALID_VALUE
,
1517 "glVertexAttribIFormat(attribindex=%u > "
1518 "GL_MAX_VERTEX_ATTRIBS)",
1523 FLUSH_VERTICES(ctx
, 0);
1525 update_array_format(ctx
, "glVertexAttribIFormat",
1526 VERT_ATTRIB_GENERIC(attribIndex
),
1527 legalTypes
, 1, 4, size
, type
, GL_FALSE
, GL_TRUE
,
1533 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1534 GLuint relativeOffset
)
1536 const GLbitfield legalTypes
= DOUBLE_BIT
;
1538 GET_CURRENT_CONTEXT(ctx
);
1539 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1541 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
1543 * "An INVALID_OPERATION error is generated under any of the following
1545 * • if no vertex array object is currently bound (see section 10.4);
1548 * This language is missing from the extension spec, but we assume
1549 * that this is an oversight.
1551 if (ctx
->API
== API_OPENGL_CORE
&&
1552 ctx
->Array
.ArrayObj
== ctx
->Array
.DefaultArrayObj
) {
1553 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1554 "glVertexAttribLFormat(No array object bound)");
1558 /* The ARB_vertex_attrib_binding spec says:
1560 * "The error INVALID_VALUE is generated if <attribindex> is greater than
1561 * or equal to the value of MAX_VERTEX_ATTRIBS."
1563 if (attribIndex
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
1564 _mesa_error(ctx
, GL_INVALID_VALUE
,
1565 "glVertexAttribLFormat(attribindex=%u > "
1566 "GL_MAX_VERTEX_ATTRIBS)",
1571 FLUSH_VERTICES(ctx
, 0);
1573 update_array_format(ctx
, "glVertexAttribLFormat",
1574 VERT_ATTRIB_GENERIC(attribIndex
),
1575 legalTypes
, 1, 4, size
, type
, GL_FALSE
, GL_FALSE
,
1581 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
1583 GET_CURRENT_CONTEXT(ctx
);
1584 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1586 /* The ARB_vertex_attrib_binding spec says:
1588 * "An INVALID_OPERATION error is generated if no vertex array object
1591 if (ctx
->API
== API_OPENGL_CORE
&&
1592 ctx
->Array
.ArrayObj
== ctx
->Array
.DefaultArrayObj
) {
1593 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1594 "glVertexAttribBinding(No array object bound)");
1598 /* The ARB_vertex_attrib_binding spec says:
1600 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1601 * <bindingindex> must be less than the value of
1602 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1605 if (attribIndex
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
1606 _mesa_error(ctx
, GL_INVALID_VALUE
,
1607 "glVertexAttribBinding(attribindex=%u >= "
1608 "GL_MAX_VERTEX_ATTRIBS)",
1613 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1614 _mesa_error(ctx
, GL_INVALID_VALUE
,
1615 "glVertexAttribBinding(bindingindex=%u >= "
1616 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1621 ASSERT(VERT_ATTRIB_GENERIC(attribIndex
) <
1622 Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
1624 vertex_attrib_binding(ctx
, VERT_ATTRIB_GENERIC(attribIndex
),
1625 VERT_ATTRIB_GENERIC(bindingIndex
));
1630 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
1632 GET_CURRENT_CONTEXT(ctx
);
1633 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1635 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1636 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexBindingDivisor()");
1640 /* The ARB_vertex_attrib_binding spec says:
1642 * "An INVALID_OPERATION error is generated if no vertex array object
1645 if (ctx
->API
== API_OPENGL_CORE
&&
1646 ctx
->Array
.ArrayObj
== ctx
->Array
.DefaultArrayObj
) {
1647 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1648 "glVertexBindingDivisor(No array object bound)");
1652 /* The ARB_vertex_attrib_binding spec says:
1654 * "An INVALID_VALUE error is generated if <bindingindex> is greater
1655 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
1657 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1658 _mesa_error(ctx
, GL_INVALID_VALUE
,
1659 "glVertexBindingDivisor(bindingindex=%u > "
1660 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1665 vertex_binding_divisor(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
1670 * Copy one client vertex array to another.
1673 _mesa_copy_client_array(struct gl_context
*ctx
,
1674 struct gl_client_array
*dst
,
1675 struct gl_client_array
*src
)
1677 dst
->Size
= src
->Size
;
1678 dst
->Type
= src
->Type
;
1679 dst
->Format
= src
->Format
;
1680 dst
->Stride
= src
->Stride
;
1681 dst
->StrideB
= src
->StrideB
;
1682 dst
->Ptr
= src
->Ptr
;
1683 dst
->Enabled
= src
->Enabled
;
1684 dst
->Normalized
= src
->Normalized
;
1685 dst
->Integer
= src
->Integer
;
1686 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1687 dst
->_ElementSize
= src
->_ElementSize
;
1688 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1689 dst
->_MaxElement
= src
->_MaxElement
;
1693 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
1694 struct gl_vertex_attrib_array
*dst
,
1695 const struct gl_vertex_attrib_array
*src
)
1697 dst
->Size
= src
->Size
;
1698 dst
->Type
= src
->Type
;
1699 dst
->Format
= src
->Format
;
1700 dst
->VertexBinding
= src
->VertexBinding
;
1701 dst
->RelativeOffset
= src
->RelativeOffset
;
1702 dst
->Format
= src
->Format
;
1703 dst
->Integer
= src
->Integer
;
1704 dst
->Normalized
= src
->Normalized
;
1705 dst
->Ptr
= src
->Ptr
;
1706 dst
->Enabled
= src
->Enabled
;
1707 dst
->_ElementSize
= src
->_ElementSize
;
1711 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
1712 struct gl_vertex_buffer_binding
*dst
,
1713 const struct gl_vertex_buffer_binding
*src
)
1715 dst
->Offset
= src
->Offset
;
1716 dst
->Stride
= src
->Stride
;
1717 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1718 dst
->_BoundArrays
= src
->_BoundArrays
;
1720 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1724 * Print vertex array's fields.
1727 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1730 printf(" %s[%d]: ", name
, index
);
1732 printf(" %s: ", name
);
1733 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
1734 array
->Ptr
, array
->Type
, array
->Size
,
1735 array
->_ElementSize
, array
->StrideB
,
1736 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
,
1737 array
->_MaxElement
);
1742 * Print current vertex object/array info. For debug.
1745 _mesa_print_arrays(struct gl_context
*ctx
)
1747 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
1750 _mesa_update_array_object_max_element(ctx
, arrayObj
);
1752 printf("Array Object %u\n", arrayObj
->Name
);
1753 if (arrayObj
->_VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
1754 print_array("Vertex", -1, &arrayObj
->_VertexAttrib
[VERT_ATTRIB_POS
]);
1755 if (arrayObj
->_VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
1756 print_array("Normal", -1, &arrayObj
->_VertexAttrib
[VERT_ATTRIB_NORMAL
]);
1757 if (arrayObj
->_VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
1758 print_array("Color", -1, &arrayObj
->_VertexAttrib
[VERT_ATTRIB_COLOR0
]);
1759 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
1760 if (arrayObj
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
1761 print_array("TexCoord", i
, &arrayObj
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
1762 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
1763 if (arrayObj
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
1764 print_array("Attrib", i
, &arrayObj
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
1765 printf(" _MaxElement = %u\n", arrayObj
->_MaxElement
);
1770 * Initialize vertex array state for given context.
1773 _mesa_init_varray(struct gl_context
*ctx
)
1775 ctx
->Array
.DefaultArrayObj
= ctx
->Driver
.NewArrayObject(ctx
, 0);
1776 _mesa_reference_array_object(ctx
, &ctx
->Array
.ArrayObj
,
1777 ctx
->Array
.DefaultArrayObj
);
1778 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1780 ctx
->Array
.Objects
= _mesa_NewHashTable();
1785 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1788 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1790 struct gl_array_object
*arrayObj
= (struct gl_array_object
*) data
;
1791 struct gl_context
*ctx
= (struct gl_context
*) userData
;
1792 _mesa_delete_array_object(ctx
, arrayObj
);
1797 * Free vertex array state for given context.
1800 _mesa_free_varray_data(struct gl_context
*ctx
)
1802 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1803 _mesa_DeleteHashTable(ctx
->Array
.Objects
);