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.
28 #include <inttypes.h> /* for PRId64 macro */
32 #include "bufferobj.h"
42 #include "main/dispatch.h"
45 /** Used to do error checking for GL_EXT_vertex_array_bgra */
49 /** Used to indicate which GL datatypes are accepted by each of the
50 * glVertex/Color/Attrib/EtcPointer() functions.
52 #define BOOL_BIT (1 << 0)
53 #define BYTE_BIT (1 << 1)
54 #define UNSIGNED_BYTE_BIT (1 << 2)
55 #define SHORT_BIT (1 << 3)
56 #define UNSIGNED_SHORT_BIT (1 << 4)
57 #define INT_BIT (1 << 5)
58 #define UNSIGNED_INT_BIT (1 << 6)
59 #define HALF_BIT (1 << 7)
60 #define FLOAT_BIT (1 << 8)
61 #define DOUBLE_BIT (1 << 9)
62 #define FIXED_ES_BIT (1 << 10)
63 #define FIXED_GL_BIT (1 << 11)
64 #define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12)
65 #define INT_2_10_10_10_REV_BIT (1 << 13)
66 #define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)
67 #define ALL_TYPE_BITS ((1 << 15) - 1)
69 #define ATTRIB_FORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
70 SHORT_BIT | UNSIGNED_SHORT_BIT | \
71 INT_BIT | UNSIGNED_INT_BIT | \
72 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | \
74 UNSIGNED_INT_2_10_10_10_REV_BIT | \
75 INT_2_10_10_10_REV_BIT | \
76 UNSIGNED_INT_10F_11F_11F_REV_BIT)
78 #define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
79 SHORT_BIT | UNSIGNED_SHORT_BIT | \
80 INT_BIT | UNSIGNED_INT_BIT)
82 #define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT
85 /** Convert GL datatype enum into a <type>_BIT value seen above */
87 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
94 case GL_UNSIGNED_BYTE
:
95 return UNSIGNED_BYTE_BIT
;
98 case GL_UNSIGNED_SHORT
:
99 return UNSIGNED_SHORT_BIT
;
102 case GL_UNSIGNED_INT
:
103 return UNSIGNED_INT_BIT
;
105 if (ctx
->Extensions
.ARB_half_float_vertex
)
114 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
115 case GL_UNSIGNED_INT_2_10_10_10_REV
:
116 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
117 case GL_INT_2_10_10_10_REV
:
118 return INT_2_10_10_10_REV_BIT
;
119 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
120 return UNSIGNED_INT_10F_11F_11F_REV_BIT
;
128 * Sets the VertexBinding field in the vertex attribute given by attribIndex.
131 vertex_attrib_binding(struct gl_context
*ctx
,
132 struct gl_vertex_array_object
*vao
,
136 struct gl_vertex_attrib_array
*array
= &vao
->VertexAttrib
[attribIndex
];
138 if (array
->VertexBinding
!= bindingIndex
) {
139 const GLbitfield64 array_bit
= VERT_BIT(attribIndex
);
141 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
143 vao
->VertexBinding
[array
->VertexBinding
]._BoundArrays
&= ~array_bit
;
144 vao
->VertexBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
146 array
->VertexBinding
= bindingIndex
;
148 vao
->NewArrays
|= array_bit
;
154 * Binds a buffer object to the vertex buffer binding point given by index,
155 * and sets the Offset and Stride fields.
158 _mesa_bind_vertex_buffer(struct gl_context
*ctx
,
159 struct gl_vertex_array_object
*vao
,
161 struct gl_buffer_object
*vbo
,
162 GLintptr offset
, GLsizei stride
)
164 struct gl_vertex_buffer_binding
*binding
= &vao
->VertexBinding
[index
];
166 if (binding
->BufferObj
!= vbo
||
167 binding
->Offset
!= offset
||
168 binding
->Stride
!= stride
) {
170 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
172 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
174 binding
->Offset
= offset
;
175 binding
->Stride
= stride
;
177 vao
->NewArrays
|= binding
->_BoundArrays
;
183 * Sets the InstanceDivisor field in the vertex buffer binding point
184 * given by bindingIndex.
187 vertex_binding_divisor(struct gl_context
*ctx
,
188 struct gl_vertex_array_object
*vao
,
192 struct gl_vertex_buffer_binding
*binding
=
193 &vao
->VertexBinding
[bindingIndex
];
195 if (binding
->InstanceDivisor
!= divisor
) {
196 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
197 binding
->InstanceDivisor
= divisor
;
198 vao
->NewArrays
|= binding
->_BoundArrays
;
204 * Examine the API profile and extensions to determine which types are legal
205 * for vertex arrays. This is called once from update_array_format().
208 get_legal_types_mask(const struct gl_context
*ctx
)
210 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
212 if (_mesa_is_gles(ctx
)) {
213 legalTypesMask
&= ~(FIXED_GL_BIT
|
215 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
217 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
218 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
219 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
220 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
221 * quite as trivial as we'd like because it uses a different enum value
222 * for GL_HALF_FLOAT_OES.
224 if (ctx
->Version
< 30) {
225 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
227 UNSIGNED_INT_2_10_10_10_REV_BIT
|
228 INT_2_10_10_10_REV_BIT
|
233 legalTypesMask
&= ~FIXED_ES_BIT
;
235 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
236 legalTypesMask
&= ~FIXED_GL_BIT
;
238 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
239 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
240 INT_2_10_10_10_REV_BIT
);
242 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
243 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
246 return legalTypesMask
;
251 * \param attrib The index of the attribute array
252 * \param size Components per element (1, 2, 3 or 4)
253 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
254 * \param format Either GL_RGBA or GL_BGRA.
255 * \param normalized Whether integer types are converted to floats in [-1, 1]
256 * \param integer Integer-valued values (will not be normalized to [-1, 1])
257 * \param doubles Double values not reduced to floats
258 * \param relativeOffset Offset of the first element relative to the binding
260 * \param flush_verties Should \c FLUSH_VERTICES be invoked before updating
264 _mesa_update_array_format(struct gl_context
*ctx
,
265 struct gl_vertex_array_object
*vao
,
266 GLuint attrib
, GLint size
, GLenum type
,
267 GLenum format
, GLboolean normalized
,
268 GLboolean integer
, GLboolean doubles
,
269 GLuint relativeOffset
, bool flush_vertices
)
271 struct gl_vertex_attrib_array
*const array
= &vao
->VertexAttrib
[attrib
];
276 if (flush_vertices
) {
277 FLUSH_VERTICES(ctx
, 0);
280 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
281 assert(elementSize
!= -1);
285 array
->Format
= format
;
286 array
->Normalized
= normalized
;
287 array
->Integer
= integer
;
288 array
->Doubles
= doubles
;
289 array
->RelativeOffset
= relativeOffset
;
290 array
->_ElementSize
= elementSize
;
292 vao
->NewArrays
|= VERT_BIT(attrib
);
293 ctx
->NewState
|= _NEW_ARRAY
;
297 * Does error checking and updates the format in an attrib array.
299 * Called by update_array() and VertexAttrib*Format().
301 * \param func Name of calling function used for error reporting
302 * \param attrib The index of the attribute array
303 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
304 * \param sizeMin Min allowable size value
305 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
306 * \param size Components per element (1, 2, 3 or 4)
307 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
308 * \param normalized Whether integer types are converted to floats in [-1, 1]
309 * \param integer Integer-valued values (will not be normalized to [-1, 1])
310 * \param doubles Double values not reduced to floats
311 * \param relativeOffset Offset of the first element relative to the binding offset.
314 update_array_format(struct gl_context
*ctx
,
316 struct gl_vertex_array_object
*vao
,
317 GLuint attrib
, GLbitfield legalTypesMask
,
318 GLint sizeMin
, GLint sizeMax
,
319 GLint size
, GLenum type
,
320 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
321 GLuint relativeOffset
)
324 GLenum format
= GL_RGBA
;
326 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
327 /* Compute the LegalTypesMask only once, unless the context API has
328 * changed, in which case we want to compute it again. We can't do this
329 * in _mesa_init_varrays() below because extensions are not yet enabled
332 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
333 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
336 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
338 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
339 /* BGRA ordering is not supported in ES contexts.
344 typeBit
= type_to_bit(ctx
, type
);
345 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
346 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
347 func
, _mesa_enum_to_string(type
));
351 /* Do size parameter checking.
352 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
353 * must be handled specially.
355 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
356 sizeMax
== BGRA_OR_4
&&
358 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
360 * "An INVALID_OPERATION error is generated under any of the following
363 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
364 * or UNSIGNED_INT_2_10_10_10_REV;
366 * • size is BGRA and normalized is FALSE;"
368 bool bgra_error
= false;
370 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
371 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
372 type
!= GL_INT_2_10_10_10_REV
&&
373 type
!= GL_UNSIGNED_BYTE
)
375 } else if (type
!= GL_UNSIGNED_BYTE
)
379 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
380 func
, _mesa_enum_to_string(type
));
385 _mesa_error(ctx
, GL_INVALID_OPERATION
,
386 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
393 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
394 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
398 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
399 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
400 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
401 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
405 /* The ARB_vertex_attrib_binding_spec says:
407 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
408 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
410 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
411 _mesa_error(ctx
, GL_INVALID_VALUE
,
412 "%s(relativeOffset=%d > "
413 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
414 func
, relativeOffset
);
418 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
419 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
420 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
424 _mesa_update_array_format(ctx
, vao
, attrib
, size
, type
, format
,
425 normalized
, integer
, doubles
, relativeOffset
,
433 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
436 * \param func name of calling function used for error reporting
437 * \param attrib the attribute array index to update
438 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
439 * \param sizeMin min allowable size value
440 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
441 * \param size components per element (1, 2, 3 or 4)
442 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
443 * \param stride stride between elements, in elements
444 * \param normalized are integer types converted to floats in [-1, 1]?
445 * \param integer integer-valued values (will not be normalized to [-1,1])
446 * \param doubles Double values not reduced to floats
447 * \param ptr the address (or offset inside VBO) of the array data
450 update_array(struct gl_context
*ctx
,
452 GLuint attrib
, GLbitfield legalTypesMask
,
453 GLint sizeMin
, GLint sizeMax
,
454 GLint size
, GLenum type
, GLsizei stride
,
455 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
458 struct gl_vertex_attrib_array
*array
;
459 GLsizei effectiveStride
;
461 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
463 * "Client vertex arrays - all vertex array attribute pointers must
464 * refer to buffer objects (section 2.9.2). The default vertex array
465 * object (the name zero) is also deprecated. Calling
466 * VertexAttribPointer when no buffer object or no vertex array object
467 * is bound will generate an INVALID_OPERATION error..."
469 * The check for VBOs is handled below.
471 if (ctx
->API
== API_OPENGL_CORE
472 && (ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
)) {
473 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
479 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
483 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
484 stride
> ctx
->Const
.MaxVertexAttribStride
) {
485 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
486 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
490 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
492 * "An INVALID_OPERATION error is generated under any of the following
497 * * any of the *Pointer commands specifying the location and
498 * organization of vertex array data are called while zero is bound
499 * to the ARRAY_BUFFER buffer object binding point (see section
500 * 2.9.6), and the pointer argument is not NULL."
502 if (ptr
!= NULL
&& ctx
->Array
.VAO
->ARBsemantics
&&
503 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
504 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
508 if (!update_array_format(ctx
, func
, ctx
->Array
.VAO
, attrib
,
509 legalTypesMask
, sizeMin
, sizeMax
,
510 size
, type
, normalized
, integer
, doubles
, 0)) {
514 /* Reset the vertex attrib binding */
515 vertex_attrib_binding(ctx
, ctx
->Array
.VAO
, attrib
, attrib
);
517 /* The Stride and Ptr fields are not set by update_array_format() */
518 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
519 array
->Stride
= stride
;
520 array
->Ptr
= (const GLvoid
*) ptr
;
522 /* Update the vertex buffer binding */
523 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
524 _mesa_bind_vertex_buffer(ctx
, ctx
->Array
.VAO
, attrib
,
525 ctx
->Array
.ArrayBufferObj
, (GLintptr
) ptr
,
531 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
533 GET_CURRENT_CONTEXT(ctx
);
534 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
535 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
536 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
537 DOUBLE_BIT
| HALF_BIT
|
538 UNSIGNED_INT_2_10_10_10_REV_BIT
|
539 INT_2_10_10_10_REV_BIT
);
541 FLUSH_VERTICES(ctx
, 0);
543 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
545 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
550 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
552 GET_CURRENT_CONTEXT(ctx
);
553 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
554 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
555 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
556 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
557 UNSIGNED_INT_2_10_10_10_REV_BIT
|
558 INT_2_10_10_10_REV_BIT
);
560 FLUSH_VERTICES(ctx
, 0);
562 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
564 3, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
569 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
571 GET_CURRENT_CONTEXT(ctx
);
572 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
573 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
574 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
575 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
576 INT_BIT
| UNSIGNED_INT_BIT
|
577 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
578 UNSIGNED_INT_2_10_10_10_REV_BIT
|
579 INT_2_10_10_10_REV_BIT
);
580 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
582 FLUSH_VERTICES(ctx
, 0);
584 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
585 legalTypes
, sizeMin
, BGRA_OR_4
,
586 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
591 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
593 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
594 GET_CURRENT_CONTEXT(ctx
);
596 FLUSH_VERTICES(ctx
, 0);
598 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
600 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
605 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
607 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
608 FLOAT_BIT
| DOUBLE_BIT
);
609 GET_CURRENT_CONTEXT(ctx
);
611 FLUSH_VERTICES(ctx
, 0);
613 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
615 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
620 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
621 GLsizei stride
, const GLvoid
*ptr
)
623 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
624 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
625 INT_BIT
| UNSIGNED_INT_BIT
|
626 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
627 UNSIGNED_INT_2_10_10_10_REV_BIT
|
628 INT_2_10_10_10_REV_BIT
);
629 GET_CURRENT_CONTEXT(ctx
);
631 FLUSH_VERTICES(ctx
, 0);
633 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
634 legalTypes
, 3, BGRA_OR_4
,
635 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
640 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
643 GET_CURRENT_CONTEXT(ctx
);
644 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
645 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
646 : (SHORT_BIT
| INT_BIT
|
647 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
648 UNSIGNED_INT_2_10_10_10_REV_BIT
|
649 INT_2_10_10_10_REV_BIT
);
650 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
651 const GLuint unit
= ctx
->Array
.ActiveTexture
;
653 FLUSH_VERTICES(ctx
, 0);
655 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
656 legalTypes
, sizeMin
, 4,
657 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
663 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
665 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
666 /* this is the same type that glEdgeFlag uses */
667 const GLboolean integer
= GL_FALSE
;
668 GET_CURRENT_CONTEXT(ctx
);
670 FLUSH_VERTICES(ctx
, 0);
672 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
674 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
679 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
681 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
682 GET_CURRENT_CONTEXT(ctx
);
684 FLUSH_VERTICES(ctx
, 0);
686 if (ctx
->API
!= API_OPENGLES
) {
687 _mesa_error(ctx
, GL_INVALID_OPERATION
,
688 "glPointSizePointer(ES 1.x only)");
692 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
694 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
699 * Set a generic vertex attribute array.
700 * Note that these arrays DO NOT alias the conventional GL vertex arrays
701 * (position, normal, color, fog, texcoord, etc).
704 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
705 GLboolean normalized
,
706 GLsizei stride
, const GLvoid
*ptr
)
708 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
709 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
710 INT_BIT
| UNSIGNED_INT_BIT
|
711 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
712 FIXED_ES_BIT
| FIXED_GL_BIT
|
713 UNSIGNED_INT_2_10_10_10_REV_BIT
|
714 INT_2_10_10_10_REV_BIT
|
715 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
716 GET_CURRENT_CONTEXT(ctx
);
718 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
719 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
723 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
724 legalTypes
, 1, BGRA_OR_4
,
725 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
730 * GL_EXT_gpu_shader4 / GL 3.0.
731 * Set an integer-valued vertex attribute array.
732 * Note that these arrays DO NOT alias the conventional GL vertex arrays
733 * (position, normal, color, fog, texcoord, etc).
736 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
737 GLsizei stride
, const GLvoid
*ptr
)
739 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
740 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
741 INT_BIT
| UNSIGNED_INT_BIT
);
742 const GLboolean normalized
= GL_FALSE
;
743 const GLboolean integer
= GL_TRUE
;
744 GET_CURRENT_CONTEXT(ctx
);
746 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
747 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
751 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
753 size
, type
, stride
, normalized
, integer
, GL_FALSE
, ptr
);
757 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
758 GLsizei stride
, const GLvoid
*ptr
)
760 GET_CURRENT_CONTEXT(ctx
);
761 const GLbitfield legalTypes
= (DOUBLE_BIT
);
762 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
763 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
767 update_array(ctx
, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index
),
769 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_TRUE
, ptr
);
774 enable_vertex_array_attrib(struct gl_context
*ctx
,
775 struct gl_vertex_array_object
*vao
,
779 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
780 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
784 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
786 if (!vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
787 /* was disabled, now being enabled */
788 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
789 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
790 vao
->_Enabled
|= VERT_BIT_GENERIC(index
);
791 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
797 _mesa_EnableVertexAttribArray(GLuint index
)
799 GET_CURRENT_CONTEXT(ctx
);
800 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
801 "glEnableVertexAttribArray");
806 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
808 GET_CURRENT_CONTEXT(ctx
);
809 struct gl_vertex_array_object
*vao
;
811 /* The ARB_direct_state_access specification says:
813 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
814 * and DisableVertexArrayAttrib if <vaobj> is not
815 * [compatibility profile: zero or] the name of an existing vertex
818 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
822 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
827 disable_vertex_array_attrib(struct gl_context
*ctx
,
828 struct gl_vertex_array_object
*vao
,
832 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
833 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
837 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
839 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
840 /* was enabled, now being disabled */
841 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
842 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
843 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
844 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
850 _mesa_DisableVertexAttribArray(GLuint index
)
852 GET_CURRENT_CONTEXT(ctx
);
853 disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
854 "glDisableVertexAttribArray");
859 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
861 GET_CURRENT_CONTEXT(ctx
);
862 struct gl_vertex_array_object
*vao
;
864 /* The ARB_direct_state_access specification says:
866 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
867 * and DisableVertexArrayAttrib if <vaobj> is not
868 * [compatibility profile: zero or] the name of an existing vertex
871 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
875 disable_vertex_array_attrib(ctx
, vao
, index
, "glDisableVertexArrayAttrib");
880 * Return info for a vertex attribute array (no alias with legacy
881 * vertex attributes (pos, normal, color, etc)). This function does
882 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
885 get_vertex_array_attrib(struct gl_context
*ctx
,
886 const struct gl_vertex_array_object
*vao
,
887 GLuint index
, GLenum pname
,
890 const struct gl_vertex_attrib_array
*array
;
892 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
893 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
897 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
899 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
902 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
903 return array
->Enabled
;
904 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
905 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
906 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
907 return array
->Stride
;
908 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
910 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
911 return array
->Normalized
;
912 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
913 return vao
->VertexBinding
[array
->VertexBinding
].BufferObj
->Name
;
914 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
915 if ((_mesa_is_desktop_gl(ctx
)
916 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
917 || _mesa_is_gles3(ctx
)) {
918 return array
->Integer
;
921 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
922 if (_mesa_is_desktop_gl(ctx
)) {
923 return array
->Doubles
;
926 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
927 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
928 || _mesa_is_gles3(ctx
)) {
929 return vao
->VertexBinding
[array
->VertexBinding
].InstanceDivisor
;
932 case GL_VERTEX_ATTRIB_BINDING
:
933 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
934 return array
->VertexBinding
- VERT_ATTRIB_GENERIC0
;
937 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
938 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
939 return array
->RelativeOffset
;
947 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
952 static const GLfloat
*
953 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
956 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
957 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
961 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
962 _mesa_error(ctx
, GL_INVALID_VALUE
,
963 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
967 assert(VERT_ATTRIB_GENERIC(index
) <
968 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
970 FLUSH_CURRENT(ctx
, 0);
971 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
975 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
977 GET_CURRENT_CONTEXT(ctx
);
979 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
980 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
986 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
988 "glGetVertexAttribfv");
994 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
996 GET_CURRENT_CONTEXT(ctx
);
998 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
999 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
1001 params
[0] = (GLdouble
) v
[0];
1002 params
[1] = (GLdouble
) v
[1];
1003 params
[2] = (GLdouble
) v
[2];
1004 params
[3] = (GLdouble
) v
[3];
1008 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1010 "glGetVertexAttribdv");
1015 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1017 GET_CURRENT_CONTEXT(ctx
);
1019 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1021 (const GLdouble
*)get_current_attrib(ctx
, index
,
1022 "glGetVertexAttribLdv");
1031 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1033 "glGetVertexAttribLdv");
1038 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
1040 GET_CURRENT_CONTEXT(ctx
);
1042 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1043 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1045 /* XXX should floats in[0,1] be scaled to full int range? */
1046 params
[0] = (GLint
) v
[0];
1047 params
[1] = (GLint
) v
[1];
1048 params
[2] = (GLint
) v
[2];
1049 params
[3] = (GLint
) v
[3];
1053 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1055 "glGetVertexAttribiv");
1062 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1064 GET_CURRENT_CONTEXT(ctx
);
1066 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1067 const GLint
*v
= (const GLint
*)
1068 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1074 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1076 "glGetVertexAttribIiv");
1083 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1085 GET_CURRENT_CONTEXT(ctx
);
1087 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1088 const GLuint
*v
= (const GLuint
*)
1089 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1095 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1097 "glGetVertexAttribIuiv");
1103 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1105 GET_CURRENT_CONTEXT(ctx
);
1107 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1108 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1112 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1113 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1117 assert(VERT_ATTRIB_GENERIC(index
) <
1118 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1120 *pointer
= (GLvoid
*)
1121 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1125 /** ARB_direct_state_access */
1127 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
1128 GLenum pname
, GLint
*params
)
1130 GET_CURRENT_CONTEXT(ctx
);
1131 struct gl_vertex_array_object
*vao
;
1133 /* The ARB_direct_state_access specification says:
1135 * "An INVALID_OPERATION error is generated if <vaobj> is not
1136 * [compatibility profile: zero or] the name of an existing
1137 * vertex array object."
1139 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexediv");
1143 /* The ARB_direct_state_access specification says:
1145 * "For GetVertexArrayIndexediv, <pname> must be one of
1146 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1147 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1148 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1149 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1150 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1154 * "Add GetVertexArrayIndexediv in 'Get Command' for
1155 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1156 * VERTEX_ATTRIB_BINDING,
1157 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1158 * VERTEX_BINDING_OFFSET, and
1159 * VERTEX_BINDING_STRIDE states"
1161 * The only parameter name common to both lists is
1162 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1163 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1164 * pretty clear however that the intent is that it should be possible
1165 * to query all vertex attrib and binding states that can be set with
1169 case GL_VERTEX_BINDING_OFFSET
:
1170 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1172 case GL_VERTEX_BINDING_STRIDE
:
1173 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
1175 case GL_VERTEX_BINDING_DIVISOR
:
1176 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
1178 case GL_VERTEX_BINDING_BUFFER
:
1179 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
1182 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
1183 "glGetVertexArrayIndexediv");
1190 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
1191 GLenum pname
, GLint64
*params
)
1193 GET_CURRENT_CONTEXT(ctx
);
1194 struct gl_vertex_array_object
*vao
;
1196 /* The ARB_direct_state_access specification says:
1198 * "An INVALID_OPERATION error is generated if <vaobj> is not
1199 * [compatibility profile: zero or] the name of an existing
1200 * vertex array object."
1202 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexed64iv");
1206 /* The ARB_direct_state_access specification says:
1208 * "For GetVertexArrayIndexed64iv, <pname> must be
1209 * VERTEX_BINDING_OFFSET."
1213 * "An INVALID_ENUM error is generated if <pname> is not one of
1214 * the valid values listed above for the corresponding command."
1216 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
1217 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
1218 "pname != GL_VERTEX_BINDING_OFFSET)");
1222 /* The ARB_direct_state_access specification says:
1224 * "An INVALID_VALUE error is generated if <index> is greater than
1225 * or equal to the value of MAX_VERTEX_ATTRIBS."
1227 * Since the index refers to a buffer binding in this case, the intended
1228 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1229 * required to be the same, so in practice this doesn't matter.
1231 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
1232 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
1233 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1234 index
, ctx
->Const
.MaxVertexAttribBindings
);
1238 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1243 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1244 GLsizei count
, const GLvoid
*ptr
)
1247 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1252 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1256 _mesa_NormalPointer(type
, stride
, ptr
);
1261 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1265 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1270 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1274 _mesa_IndexPointer(type
, stride
, ptr
);
1279 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1280 GLsizei count
, const GLvoid
*ptr
)
1283 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1288 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1291 _mesa_EdgeFlagPointer(stride
, ptr
);
1296 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1298 GET_CURRENT_CONTEXT(ctx
);
1299 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1300 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1301 GLenum ctype
= 0; /* color type */
1302 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1303 const GLint toffset
= 0; /* always zero */
1304 GLint defstride
; /* default stride */
1307 FLUSH_VERTICES(ctx
, 0);
1309 f
= sizeof(GLfloat
);
1310 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1313 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1319 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1320 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1325 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1326 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1331 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1332 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1333 ctype
= GL_UNSIGNED_BYTE
;
1336 defstride
= c
+ 2*f
;
1339 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1340 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1341 ctype
= GL_UNSIGNED_BYTE
;
1344 defstride
= c
+ 3*f
;
1347 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1348 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1355 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1356 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1361 case GL_C4F_N3F_V3F
:
1362 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1363 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1371 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1372 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1377 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1378 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1382 case GL_T2F_C4UB_V3F
:
1383 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1384 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1385 ctype
= GL_UNSIGNED_BYTE
;
1390 case GL_T2F_C3F_V3F
:
1391 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1392 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1398 case GL_T2F_N3F_V3F
:
1399 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1400 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1405 case GL_T2F_C4F_N3F_V3F
:
1406 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1407 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1414 case GL_T4F_C4F_N3F_V4F
:
1415 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1416 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1424 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1432 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1433 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1434 /* XXX also disable secondary color and generic arrays? */
1438 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1439 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1440 (GLubyte
*) pointer
+ toffset
);
1443 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1448 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1449 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1450 (GLubyte
*) pointer
+ coffset
);
1453 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1459 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1460 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1463 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1467 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1468 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1469 (GLubyte
*) pointer
+ voffset
);
1474 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1476 GET_CURRENT_CONTEXT(ctx
);
1478 FLUSH_VERTICES(ctx
, 0);
1480 if (MESA_VERBOSE
& VERBOSE_API
)
1481 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1484 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1488 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1491 if (ctx
->Array
.LockCount
!= 0) {
1492 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1496 ctx
->Array
.LockFirst
= first
;
1497 ctx
->Array
.LockCount
= count
;
1499 ctx
->NewState
|= _NEW_ARRAY
;
1504 _mesa_UnlockArraysEXT( void )
1506 GET_CURRENT_CONTEXT(ctx
);
1508 FLUSH_VERTICES(ctx
, 0);
1510 if (MESA_VERBOSE
& VERBOSE_API
)
1511 _mesa_debug(ctx
, "glUnlockArrays\n");
1513 if (ctx
->Array
.LockCount
== 0) {
1514 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1518 ctx
->Array
.LockFirst
= 0;
1519 ctx
->Array
.LockCount
= 0;
1520 ctx
->NewState
|= _NEW_ARRAY
;
1524 /* GL_EXT_multi_draw_arrays */
1526 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1527 const GLsizei
*count
, GLsizei primcount
)
1529 GET_CURRENT_CONTEXT(ctx
);
1532 FLUSH_VERTICES(ctx
, 0);
1534 for (i
= 0; i
< primcount
; i
++) {
1536 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1542 /* GL_IBM_multimode_draw_arrays */
1544 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1545 const GLsizei
* count
,
1546 GLsizei primcount
, GLint modestride
)
1548 GET_CURRENT_CONTEXT(ctx
);
1551 FLUSH_VERTICES(ctx
, 0);
1553 for ( i
= 0 ; i
< primcount
; i
++ ) {
1554 if ( count
[i
] > 0 ) {
1555 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1556 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1562 /* GL_IBM_multimode_draw_arrays */
1564 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1565 GLenum type
, const GLvoid
* const * indices
,
1566 GLsizei primcount
, GLint modestride
)
1568 GET_CURRENT_CONTEXT(ctx
);
1571 FLUSH_VERTICES(ctx
, 0);
1573 /* XXX not sure about ARB_vertex_buffer_object handling here */
1575 for ( i
= 0 ; i
< primcount
; i
++ ) {
1576 if ( count
[i
] > 0 ) {
1577 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1578 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1586 * GL_NV_primitive_restart and GL 3.1
1589 _mesa_PrimitiveRestartIndex(GLuint index
)
1591 GET_CURRENT_CONTEXT(ctx
);
1593 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1594 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1598 if (ctx
->Array
.RestartIndex
!= index
) {
1599 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1600 ctx
->Array
.RestartIndex
= index
;
1606 * See GL_ARB_instanced_arrays.
1607 * Note that the instance divisor only applies to generic arrays, not
1608 * the legacy vertex arrays.
1611 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1613 GET_CURRENT_CONTEXT(ctx
);
1615 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1616 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1618 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1619 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1623 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1624 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1629 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
1631 /* The ARB_vertex_attrib_binding spec says:
1635 * void VertexAttribDivisor(uint index, uint divisor);
1637 * is equivalent to (assuming no errors are generated):
1639 * VertexAttribBinding(index, index);
1640 * VertexBindingDivisor(index, divisor);"
1642 vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
1643 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
1648 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1650 /* From the OpenGL 4.3 core specification, page 302:
1651 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1652 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1655 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1657 case GL_UNSIGNED_BYTE
:
1659 case GL_UNSIGNED_SHORT
:
1661 case GL_UNSIGNED_INT
:
1664 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1668 return ctx
->Array
.RestartIndex
;
1673 * GL_ARB_vertex_attrib_binding
1676 vertex_array_vertex_buffer(struct gl_context
*ctx
,
1677 struct gl_vertex_array_object
*vao
,
1678 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1679 GLsizei stride
, const char *func
)
1681 struct gl_buffer_object
*vbo
;
1683 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1685 /* The ARB_vertex_attrib_binding spec says:
1687 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1688 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1690 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1691 _mesa_error(ctx
, GL_INVALID_VALUE
,
1692 "%s(bindingindex=%u > "
1693 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1694 func
, bindingIndex
);
1698 /* The ARB_vertex_attrib_binding spec says:
1700 * "The error INVALID_VALUE is generated if <stride> or <offset>
1704 _mesa_error(ctx
, GL_INVALID_VALUE
,
1705 "%s(offset=%" PRId64
" < 0)",
1706 func
, (int64_t) offset
);
1711 _mesa_error(ctx
, GL_INVALID_VALUE
,
1712 "%s(stride=%d < 0)", func
, stride
);
1716 if (((ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
1717 stride
> ctx
->Const
.MaxVertexAttribStride
) {
1718 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
1719 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
1724 vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1725 vbo
= vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1726 } else if (buffer
!= 0) {
1727 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1729 /* From the GL_ARB_vertex_attrib_array spec:
1731 * "[Core profile only:]
1732 * An INVALID_OPERATION error is generated if buffer is not zero or a
1733 * name returned from a previous call to GenBuffers, or if such a name
1734 * has since been deleted with DeleteBuffers.
1736 * Otherwise, we fall back to the same compat profile behavior as other
1737 * object references (automatically gen it).
1739 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
1742 /* The ARB_vertex_attrib_binding spec says:
1744 * "If <buffer> is zero, any buffer object attached to this
1745 * bindpoint is detached."
1747 vbo
= ctx
->Shared
->NullBufferObj
;
1750 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
1751 vbo
, offset
, stride
);
1756 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1759 GET_CURRENT_CONTEXT(ctx
);
1761 /* The ARB_vertex_attrib_binding spec says:
1763 * "An INVALID_OPERATION error is generated if no vertex array object
1766 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
1767 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1768 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1769 "glBindVertexBuffer(No array object bound)");
1773 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
1774 buffer
, offset
, stride
, "glBindVertexBuffer");
1779 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
1780 GLintptr offset
, GLsizei stride
)
1782 GET_CURRENT_CONTEXT(ctx
);
1783 struct gl_vertex_array_object
*vao
;
1785 /* The ARB_direct_state_access specification says:
1787 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1788 * if <vaobj> is not [compatibility profile: zero or] the name of an
1789 * existing vertex array object."
1791 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
1795 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
,
1796 buffer
, offset
, stride
,
1797 "glVertexArrayVertexBuffer");
1802 vertex_array_vertex_buffers(struct gl_context
*ctx
,
1803 struct gl_vertex_array_object
*vao
,
1804 GLuint first
, GLsizei count
, const GLuint
*buffers
,
1805 const GLintptr
*offsets
, const GLsizei
*strides
,
1810 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1812 /* The ARB_multi_bind spec says:
1814 * "An INVALID_OPERATION error is generated if <first> + <count>
1815 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1817 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1818 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1819 "%s(first=%u + count=%d > the value of "
1820 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1821 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1827 * The ARB_multi_bind spec says:
1829 * "If <buffers> is NULL, each affected vertex buffer binding point
1830 * from <first> through <first>+<count>-1 will be reset to have no
1831 * bound buffer object. In this case, the offsets and strides
1832 * associated with the binding points are set to default values,
1833 * ignoring <offsets> and <strides>."
1835 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1837 for (i
= 0; i
< count
; i
++)
1838 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1844 /* Note that the error semantics for multi-bind commands differ from
1845 * those of other GL commands.
1847 * The Issues section in the ARB_multi_bind spec says:
1849 * "(11) Typically, OpenGL specifies that if an error is generated by
1850 * a command, that command has no effect. This is somewhat
1851 * unfortunate for multi-bind commands, because it would require
1852 * a first pass to scan the entire list of bound objects for
1853 * errors and then a second pass to actually perform the
1854 * bindings. Should we have different error semantics?
1856 * RESOLVED: Yes. In this specification, when the parameters for
1857 * one of the <count> binding points are invalid, that binding
1858 * point is not updated and an error will be generated. However,
1859 * other binding points in the same command will be updated if
1860 * their parameters are valid and no other error occurs."
1863 _mesa_begin_bufferobj_lookups(ctx
);
1865 for (i
= 0; i
< count
; i
++) {
1866 struct gl_buffer_object
*vbo
;
1868 /* The ARB_multi_bind spec says:
1870 * "An INVALID_VALUE error is generated if any value in
1871 * <offsets> or <strides> is negative (per binding)."
1873 if (offsets
[i
] < 0) {
1874 _mesa_error(ctx
, GL_INVALID_VALUE
,
1875 "%s(offsets[%u]=%" PRId64
" < 0)",
1876 func
, i
, (int64_t) offsets
[i
]);
1880 if (strides
[i
] < 0) {
1881 _mesa_error(ctx
, GL_INVALID_VALUE
,
1882 "%s(strides[%u]=%d < 0)",
1883 func
, i
, strides
[i
]);
1887 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1888 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
1889 _mesa_error(ctx
, GL_INVALID_VALUE
,
1890 "%s(strides[%u]=%d > "
1891 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
1896 struct gl_vertex_buffer_binding
*binding
=
1897 &vao
->VertexBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1899 if (buffers
[i
] == binding
->BufferObj
->Name
)
1900 vbo
= binding
->BufferObj
;
1902 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
1907 vbo
= ctx
->Shared
->NullBufferObj
;
1910 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1911 vbo
, offsets
[i
], strides
[i
]);
1914 _mesa_end_bufferobj_lookups(ctx
);
1919 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1920 const GLintptr
*offsets
, const GLsizei
*strides
)
1922 GET_CURRENT_CONTEXT(ctx
);
1924 /* The ARB_vertex_attrib_binding spec says:
1926 * "An INVALID_OPERATION error is generated if no
1927 * vertex array object is bound."
1929 if (ctx
->API
== API_OPENGL_CORE
&&
1930 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1931 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1932 "glBindVertexBuffers(No array object bound)");
1936 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
1937 buffers
, offsets
, strides
,
1938 "glBindVertexBuffers");
1943 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
1944 const GLuint
*buffers
,
1945 const GLintptr
*offsets
, const GLsizei
*strides
)
1947 GET_CURRENT_CONTEXT(ctx
);
1948 struct gl_vertex_array_object
*vao
;
1950 /* The ARB_direct_state_access specification says:
1952 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1953 * if <vaobj> is not [compatibility profile: zero or] the name of an
1954 * existing vertex array object."
1956 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
1960 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
1961 buffers
, offsets
, strides
,
1962 "glVertexArrayVertexBuffers");
1967 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
1968 GLboolean normalized
, GLboolean integer
,
1969 GLboolean doubles
, GLbitfield legalTypes
,
1970 GLsizei maxSize
, GLuint relativeOffset
,
1973 GET_CURRENT_CONTEXT(ctx
);
1974 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1976 /* The ARB_vertex_attrib_binding spec says:
1978 * "An INVALID_OPERATION error is generated under any of the following
1980 * - if no vertex array object is currently bound (see section 2.10);
1983 * This error condition only applies to VertexAttribFormat and
1984 * VertexAttribIFormat in the extension spec, but we assume that this
1985 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
1986 * to all three functions.
1988 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
1989 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1990 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1991 "%s(No array object bound)", func
);
1995 /* The ARB_vertex_attrib_binding spec says:
1997 * "The error INVALID_VALUE is generated if index is greater than or equal
1998 * to the value of MAX_VERTEX_ATTRIBS."
2000 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2001 _mesa_error(ctx
, GL_INVALID_VALUE
,
2002 "%s(attribindex=%u > "
2003 "GL_MAX_VERTEX_ATTRIBS)",
2008 FLUSH_VERTICES(ctx
, 0);
2010 update_array_format(ctx
, func
, ctx
->Array
.VAO
,
2011 VERT_ATTRIB_GENERIC(attribIndex
),
2012 legalTypes
, 1, maxSize
, size
, type
,
2013 normalized
, integer
, doubles
, relativeOffset
);
2018 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2019 GLboolean normalized
, GLuint relativeOffset
)
2021 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
2022 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2023 BGRA_OR_4
, relativeOffset
,
2024 "glVertexAttribFormat");
2029 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2030 GLuint relativeOffset
)
2032 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
2033 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
2034 relativeOffset
, "glVertexAttribIFormat");
2039 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2040 GLuint relativeOffset
)
2042 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
2043 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
2044 relativeOffset
, "glVertexAttribLFormat");
2049 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2050 GLenum type
, GLboolean normalized
,
2051 GLboolean integer
, GLboolean doubles
,
2052 GLbitfield legalTypes
, GLsizei maxSize
,
2053 GLuint relativeOffset
, const char *func
)
2055 GET_CURRENT_CONTEXT(ctx
);
2056 struct gl_vertex_array_object
*vao
;
2058 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2060 /* The ARB_direct_state_access spec says:
2062 * "An INVALID_OPERATION error is generated by VertexArrayAttrib*Format
2063 * if <vaobj> is not [compatibility profile: zero or] the name of an
2064 * existing vertex array object."
2066 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
2070 /* The ARB_vertex_attrib_binding spec says:
2072 * "The error INVALID_VALUE is generated if index is greater than or equal
2073 * to the value of MAX_VERTEX_ATTRIBS."
2075 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2076 _mesa_error(ctx
, GL_INVALID_VALUE
,
2077 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2082 FLUSH_VERTICES(ctx
, 0);
2084 update_array_format(ctx
, func
, vao
,
2085 VERT_ATTRIB_GENERIC(attribIndex
),
2086 legalTypes
, 1, maxSize
, size
, type
, normalized
,
2087 integer
, doubles
, relativeOffset
);
2092 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2093 GLenum type
, GLboolean normalized
,
2094 GLuint relativeOffset
)
2096 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
2097 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2098 BGRA_OR_4
, relativeOffset
,
2099 "glVertexArrayAttribFormat");
2104 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
2105 GLint size
, GLenum type
,
2106 GLuint relativeOffset
)
2108 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2109 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
2111 "glVertexArrayAttribIFormat");
2116 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
2117 GLint size
, GLenum type
,
2118 GLuint relativeOffset
)
2120 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2121 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
2123 "glVertexArrayAttribLFormat");
2128 vertex_array_attrib_binding(struct gl_context
*ctx
,
2129 struct gl_vertex_array_object
*vao
,
2130 GLuint attribIndex
, GLuint bindingIndex
,
2133 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2135 /* The ARB_vertex_attrib_binding spec says:
2137 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2138 * <bindingindex> must be less than the value of
2139 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2142 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2143 _mesa_error(ctx
, GL_INVALID_VALUE
,
2144 "%s(attribindex=%u >= "
2145 "GL_MAX_VERTEX_ATTRIBS)",
2150 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2151 _mesa_error(ctx
, GL_INVALID_VALUE
,
2152 "%s(bindingindex=%u >= "
2153 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2154 func
, bindingIndex
);
2158 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
2160 vertex_attrib_binding(ctx
, vao
,
2161 VERT_ATTRIB_GENERIC(attribIndex
),
2162 VERT_ATTRIB_GENERIC(bindingIndex
));
2167 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2169 GET_CURRENT_CONTEXT(ctx
);
2171 /* The ARB_vertex_attrib_binding spec says:
2173 * "An INVALID_OPERATION error is generated if no vertex array object
2176 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2177 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2178 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2179 "glVertexAttribBinding(No array object bound)");
2183 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2184 attribIndex
, bindingIndex
,
2185 "glVertexAttribBinding");
2190 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2192 GET_CURRENT_CONTEXT(ctx
);
2193 struct gl_vertex_array_object
*vao
;
2195 /* The ARB_direct_state_access specification says:
2197 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2198 * if <vaobj> is not [compatibility profile: zero or] the name of an
2199 * existing vertex array object."
2201 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2205 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2206 "glVertexArrayAttribBinding");
2211 vertex_array_binding_divisor(struct gl_context
*ctx
,
2212 struct gl_vertex_array_object
*vao
,
2213 GLuint bindingIndex
, GLuint divisor
,
2216 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2218 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2219 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
2223 /* The ARB_vertex_attrib_binding spec says:
2225 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2226 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2228 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2229 _mesa_error(ctx
, GL_INVALID_VALUE
,
2230 "%s(bindingindex=%u > "
2231 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2232 func
, bindingIndex
);
2236 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2241 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2243 GET_CURRENT_CONTEXT(ctx
);
2245 /* The ARB_vertex_attrib_binding spec says:
2247 * "An INVALID_OPERATION error is generated if no vertex array object
2250 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2251 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2252 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2253 "glVertexBindingDivisor(No array object bound)");
2257 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
2258 bindingIndex
, divisor
,
2259 "glVertexBindingDivisor");
2264 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
2267 struct gl_vertex_array_object
*vao
;
2268 GET_CURRENT_CONTEXT(ctx
);
2270 /* The ARB_direct_state_access specification says:
2272 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2273 * if <vaobj> is not [compatibility profile: zero or] the name of an
2274 * existing vertex array object."
2276 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayBindingDivisor");
2280 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
2281 "glVertexArrayBindingDivisor");
2286 * Copy one client vertex array to another.
2289 _mesa_copy_client_array(struct gl_context
*ctx
,
2290 struct gl_client_array
*dst
,
2291 struct gl_client_array
*src
)
2293 dst
->Size
= src
->Size
;
2294 dst
->Type
= src
->Type
;
2295 dst
->Format
= src
->Format
;
2296 dst
->Stride
= src
->Stride
;
2297 dst
->StrideB
= src
->StrideB
;
2298 dst
->Ptr
= src
->Ptr
;
2299 dst
->Enabled
= src
->Enabled
;
2300 dst
->Normalized
= src
->Normalized
;
2301 dst
->Integer
= src
->Integer
;
2302 dst
->Doubles
= src
->Doubles
;
2303 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2304 dst
->_ElementSize
= src
->_ElementSize
;
2305 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2309 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2310 struct gl_vertex_attrib_array
*dst
,
2311 const struct gl_vertex_attrib_array
*src
)
2313 dst
->Size
= src
->Size
;
2314 dst
->Type
= src
->Type
;
2315 dst
->Format
= src
->Format
;
2316 dst
->VertexBinding
= src
->VertexBinding
;
2317 dst
->RelativeOffset
= src
->RelativeOffset
;
2318 dst
->Format
= src
->Format
;
2319 dst
->Integer
= src
->Integer
;
2320 dst
->Doubles
= src
->Doubles
;
2321 dst
->Normalized
= src
->Normalized
;
2322 dst
->Ptr
= src
->Ptr
;
2323 dst
->Enabled
= src
->Enabled
;
2324 dst
->_ElementSize
= src
->_ElementSize
;
2328 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2329 struct gl_vertex_buffer_binding
*dst
,
2330 const struct gl_vertex_buffer_binding
*src
)
2332 dst
->Offset
= src
->Offset
;
2333 dst
->Stride
= src
->Stride
;
2334 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2335 dst
->_BoundArrays
= src
->_BoundArrays
;
2337 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2341 * Print vertex array's fields.
2344 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
2347 fprintf(stderr
, " %s[%d]: ", name
, index
);
2349 fprintf(stderr
, " %s: ", name
);
2350 fprintf(stderr
, "Ptr=%p, Type=%s, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
2351 array
->Ptr
, _mesa_enum_to_string(array
->Type
), array
->Size
,
2352 array
->_ElementSize
, array
->StrideB
, array
->BufferObj
->Name
,
2353 (unsigned long) array
->BufferObj
->Size
);
2358 * Print current vertex object/array info. For debug.
2361 _mesa_print_arrays(struct gl_context
*ctx
)
2363 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2366 printf("Array Object %u\n", vao
->Name
);
2367 if (vao
->_VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
2368 print_array("Vertex", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_POS
]);
2369 if (vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
2370 print_array("Normal", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
]);
2371 if (vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
2372 print_array("Color", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
]);
2373 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
2374 if (vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
2375 print_array("TexCoord", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
2376 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
2377 if (vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
2378 print_array("Attrib", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
2383 * Initialize vertex array state for given context.
2386 _mesa_init_varray(struct gl_context
*ctx
)
2388 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
2389 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2390 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2392 ctx
->Array
.Objects
= _mesa_NewHashTable();
2397 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2400 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2402 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2403 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2404 _mesa_delete_vao(ctx
, vao
);
2409 * Free vertex array state for given context.
2412 _mesa_free_varray_data(struct gl_context
*ctx
)
2414 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2415 _mesa_DeleteHashTable(ctx
->Array
.Objects
);