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_array_attributes
*array
= &vao
->VertexAttrib
[attribIndex
];
138 if (!_mesa_is_bufferobj(vao
->VertexBinding
[bindingIndex
].BufferObj
))
139 vao
->VertexAttribBufferMask
&= ~VERT_BIT(attribIndex
);
141 vao
->VertexAttribBufferMask
|= VERT_BIT(attribIndex
);
143 if (array
->BufferBindingIndex
!= bindingIndex
) {
144 const GLbitfield64 array_bit
= VERT_BIT(attribIndex
);
146 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
148 vao
->VertexBinding
[array
->BufferBindingIndex
]._BoundArrays
&= ~array_bit
;
149 vao
->VertexBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
151 array
->BufferBindingIndex
= bindingIndex
;
153 vao
->NewArrays
|= array_bit
;
159 * Binds a buffer object to the vertex buffer binding point given by index,
160 * and sets the Offset and Stride fields.
163 _mesa_bind_vertex_buffer(struct gl_context
*ctx
,
164 struct gl_vertex_array_object
*vao
,
166 struct gl_buffer_object
*vbo
,
167 GLintptr offset
, GLsizei stride
)
169 struct gl_vertex_buffer_binding
*binding
= &vao
->VertexBinding
[index
];
171 if (binding
->BufferObj
!= vbo
||
172 binding
->Offset
!= offset
||
173 binding
->Stride
!= stride
) {
175 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
177 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
179 binding
->Offset
= offset
;
180 binding
->Stride
= stride
;
182 if (!_mesa_is_bufferobj(vbo
))
183 vao
->VertexAttribBufferMask
&= ~binding
->_BoundArrays
;
185 vao
->VertexAttribBufferMask
|= binding
->_BoundArrays
;
187 vao
->NewArrays
|= binding
->_BoundArrays
;
193 * Sets the InstanceDivisor field in the vertex buffer binding point
194 * given by bindingIndex.
197 vertex_binding_divisor(struct gl_context
*ctx
,
198 struct gl_vertex_array_object
*vao
,
202 struct gl_vertex_buffer_binding
*binding
=
203 &vao
->VertexBinding
[bindingIndex
];
205 if (binding
->InstanceDivisor
!= divisor
) {
206 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
207 binding
->InstanceDivisor
= divisor
;
208 vao
->NewArrays
|= binding
->_BoundArrays
;
214 * Examine the API profile and extensions to determine which types are legal
215 * for vertex arrays. This is called once from update_array_format().
218 get_legal_types_mask(const struct gl_context
*ctx
)
220 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
222 if (_mesa_is_gles(ctx
)) {
223 legalTypesMask
&= ~(FIXED_GL_BIT
|
225 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
227 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
228 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
229 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
230 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
231 * quite as trivial as we'd like because it uses a different enum value
232 * for GL_HALF_FLOAT_OES.
234 if (ctx
->Version
< 30) {
235 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
237 UNSIGNED_INT_2_10_10_10_REV_BIT
|
238 INT_2_10_10_10_REV_BIT
|
243 legalTypesMask
&= ~FIXED_ES_BIT
;
245 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
246 legalTypesMask
&= ~FIXED_GL_BIT
;
248 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
249 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
250 INT_2_10_10_10_REV_BIT
);
252 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
253 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
256 return legalTypesMask
;
261 * \param attrib The index of the attribute array
262 * \param size Components per element (1, 2, 3 or 4)
263 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
264 * \param format Either GL_RGBA or GL_BGRA.
265 * \param normalized Whether integer types are converted to floats in [-1, 1]
266 * \param integer Integer-valued values (will not be normalized to [-1, 1])
267 * \param doubles Double values not reduced to floats
268 * \param relativeOffset Offset of the first element relative to the binding
270 * \param flush_verties Should \c FLUSH_VERTICES be invoked before updating
274 _mesa_update_array_format(struct gl_context
*ctx
,
275 struct gl_vertex_array_object
*vao
,
276 GLuint attrib
, GLint size
, GLenum type
,
277 GLenum format
, GLboolean normalized
,
278 GLboolean integer
, GLboolean doubles
,
279 GLuint relativeOffset
, bool flush_vertices
)
281 struct gl_array_attributes
*const array
= &vao
->VertexAttrib
[attrib
];
286 if (flush_vertices
) {
287 FLUSH_VERTICES(ctx
, 0);
290 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
291 assert(elementSize
!= -1);
295 array
->Format
= format
;
296 array
->Normalized
= normalized
;
297 array
->Integer
= integer
;
298 array
->Doubles
= doubles
;
299 array
->RelativeOffset
= relativeOffset
;
300 array
->_ElementSize
= elementSize
;
302 vao
->NewArrays
|= VERT_BIT(attrib
);
303 ctx
->NewState
|= _NEW_ARRAY
;
307 * Does error checking and updates the format in an attrib array.
309 * Called by update_array() and VertexAttrib*Format().
311 * \param func Name of calling function used for error reporting
312 * \param attrib The index of the attribute array
313 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
314 * \param sizeMin Min allowable size value
315 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
316 * \param size Components per element (1, 2, 3 or 4)
317 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
318 * \param normalized Whether integer types are converted to floats in [-1, 1]
319 * \param integer Integer-valued values (will not be normalized to [-1, 1])
320 * \param doubles Double values not reduced to floats
321 * \param relativeOffset Offset of the first element relative to the binding offset.
324 update_array_format(struct gl_context
*ctx
,
326 struct gl_vertex_array_object
*vao
,
327 GLuint attrib
, GLbitfield legalTypesMask
,
328 GLint sizeMin
, GLint sizeMax
,
329 GLint size
, GLenum type
,
330 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
331 GLuint relativeOffset
)
334 GLenum format
= GL_RGBA
;
336 /* at most, one of these bools can be true */
337 assert((int) normalized
+ (int) integer
+ (int) doubles
<= 1);
339 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
340 /* Compute the LegalTypesMask only once, unless the context API has
341 * changed, in which case we want to compute it again. We can't do this
342 * in _mesa_init_varrays() below because extensions are not yet enabled
345 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
346 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
349 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
351 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
352 /* BGRA ordering is not supported in ES contexts.
357 typeBit
= type_to_bit(ctx
, type
);
358 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
359 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
360 func
, _mesa_enum_to_string(type
));
364 /* Do size parameter checking.
365 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
366 * must be handled specially.
368 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
369 sizeMax
== BGRA_OR_4
&&
371 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
373 * "An INVALID_OPERATION error is generated under any of the following
376 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
377 * or UNSIGNED_INT_2_10_10_10_REV;
379 * • size is BGRA and normalized is FALSE;"
381 bool bgra_error
= false;
383 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
384 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
385 type
!= GL_INT_2_10_10_10_REV
&&
386 type
!= GL_UNSIGNED_BYTE
)
388 } else if (type
!= GL_UNSIGNED_BYTE
)
392 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
393 func
, _mesa_enum_to_string(type
));
398 _mesa_error(ctx
, GL_INVALID_OPERATION
,
399 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
406 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
407 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
411 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
412 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
413 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
414 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
418 /* The ARB_vertex_attrib_binding_spec says:
420 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
421 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
423 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
424 _mesa_error(ctx
, GL_INVALID_VALUE
,
425 "%s(relativeOffset=%d > "
426 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
427 func
, relativeOffset
);
431 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
432 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
433 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
437 _mesa_update_array_format(ctx
, vao
, attrib
, size
, type
, format
,
438 normalized
, integer
, doubles
, relativeOffset
,
446 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
449 * \param func name of calling function used for error reporting
450 * \param attrib the attribute array index to update
451 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
452 * \param sizeMin min allowable size value
453 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
454 * \param size components per element (1, 2, 3 or 4)
455 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
456 * \param stride stride between elements, in elements
457 * \param normalized are integer types converted to floats in [-1, 1]?
458 * \param integer integer-valued values (will not be normalized to [-1,1])
459 * \param doubles Double values not reduced to floats
460 * \param ptr the address (or offset inside VBO) of the array data
463 update_array(struct gl_context
*ctx
,
465 GLuint attrib
, GLbitfield legalTypesMask
,
466 GLint sizeMin
, GLint sizeMax
,
467 GLint size
, GLenum type
, GLsizei stride
,
468 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
471 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
472 struct gl_array_attributes
*array
;
473 GLsizei effectiveStride
;
475 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
477 * "Client vertex arrays - all vertex array attribute pointers must
478 * refer to buffer objects (section 2.9.2). The default vertex array
479 * object (the name zero) is also deprecated. Calling
480 * VertexAttribPointer when no buffer object or no vertex array object
481 * is bound will generate an INVALID_OPERATION error..."
483 * The check for VBOs is handled below.
485 if (ctx
->API
== API_OPENGL_CORE
&& (vao
== ctx
->Array
.DefaultVAO
)) {
486 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
492 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
496 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
497 stride
> ctx
->Const
.MaxVertexAttribStride
) {
498 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
499 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
503 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
505 * "An INVALID_OPERATION error is generated under any of the following
510 * * any of the *Pointer commands specifying the location and
511 * organization of vertex array data are called while zero is bound
512 * to the ARRAY_BUFFER buffer object binding point (see section
513 * 2.9.6), and the pointer argument is not NULL."
515 if (ptr
!= NULL
&& vao
->ARBsemantics
&&
516 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
517 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
521 if (!update_array_format(ctx
, func
, vao
, attrib
,
522 legalTypesMask
, sizeMin
, sizeMax
,
523 size
, type
, normalized
, integer
, doubles
, 0)) {
527 /* Reset the vertex attrib binding */
528 vertex_attrib_binding(ctx
, vao
, attrib
, attrib
);
530 /* The Stride and Ptr fields are not set by update_array_format() */
531 array
= &vao
->VertexAttrib
[attrib
];
532 array
->Stride
= stride
;
535 /* Update the vertex buffer binding */
536 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
537 _mesa_bind_vertex_buffer(ctx
, vao
, attrib
,
538 ctx
->Array
.ArrayBufferObj
, (GLintptr
) ptr
,
544 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
546 GET_CURRENT_CONTEXT(ctx
);
547 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
548 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
549 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
550 DOUBLE_BIT
| HALF_BIT
|
551 UNSIGNED_INT_2_10_10_10_REV_BIT
|
552 INT_2_10_10_10_REV_BIT
);
554 FLUSH_VERTICES(ctx
, 0);
556 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
558 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
563 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
565 GET_CURRENT_CONTEXT(ctx
);
566 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
567 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
568 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
569 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
570 UNSIGNED_INT_2_10_10_10_REV_BIT
|
571 INT_2_10_10_10_REV_BIT
);
573 FLUSH_VERTICES(ctx
, 0);
575 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
577 3, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
582 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
584 GET_CURRENT_CONTEXT(ctx
);
585 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
586 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
587 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
588 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
589 INT_BIT
| UNSIGNED_INT_BIT
|
590 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
591 UNSIGNED_INT_2_10_10_10_REV_BIT
|
592 INT_2_10_10_10_REV_BIT
);
593 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
595 FLUSH_VERTICES(ctx
, 0);
597 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
598 legalTypes
, sizeMin
, BGRA_OR_4
,
599 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
604 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
606 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
607 GET_CURRENT_CONTEXT(ctx
);
609 FLUSH_VERTICES(ctx
, 0);
611 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
613 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
618 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
620 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
621 FLOAT_BIT
| DOUBLE_BIT
);
622 GET_CURRENT_CONTEXT(ctx
);
624 FLUSH_VERTICES(ctx
, 0);
626 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
628 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
633 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
634 GLsizei stride
, const GLvoid
*ptr
)
636 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
637 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
638 INT_BIT
| UNSIGNED_INT_BIT
|
639 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
640 UNSIGNED_INT_2_10_10_10_REV_BIT
|
641 INT_2_10_10_10_REV_BIT
);
642 GET_CURRENT_CONTEXT(ctx
);
644 FLUSH_VERTICES(ctx
, 0);
646 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
647 legalTypes
, 3, BGRA_OR_4
,
648 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
653 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
656 GET_CURRENT_CONTEXT(ctx
);
657 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
658 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
659 : (SHORT_BIT
| INT_BIT
|
660 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
661 UNSIGNED_INT_2_10_10_10_REV_BIT
|
662 INT_2_10_10_10_REV_BIT
);
663 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
664 const GLuint unit
= ctx
->Array
.ActiveTexture
;
666 FLUSH_VERTICES(ctx
, 0);
668 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
669 legalTypes
, sizeMin
, 4,
670 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
676 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
678 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
679 /* this is the same type that glEdgeFlag uses */
680 const GLboolean integer
= GL_FALSE
;
681 GET_CURRENT_CONTEXT(ctx
);
683 FLUSH_VERTICES(ctx
, 0);
685 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
687 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
692 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
694 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
695 GET_CURRENT_CONTEXT(ctx
);
697 FLUSH_VERTICES(ctx
, 0);
699 if (ctx
->API
!= API_OPENGLES
) {
700 _mesa_error(ctx
, GL_INVALID_OPERATION
,
701 "glPointSizePointer(ES 1.x only)");
705 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
707 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
712 * Set a generic vertex attribute array.
713 * Note that these arrays DO NOT alias the conventional GL vertex arrays
714 * (position, normal, color, fog, texcoord, etc).
717 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
718 GLboolean normalized
,
719 GLsizei stride
, const GLvoid
*ptr
)
721 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
722 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
723 INT_BIT
| UNSIGNED_INT_BIT
|
724 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
725 FIXED_ES_BIT
| FIXED_GL_BIT
|
726 UNSIGNED_INT_2_10_10_10_REV_BIT
|
727 INT_2_10_10_10_REV_BIT
|
728 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
729 GET_CURRENT_CONTEXT(ctx
);
731 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
732 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
736 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
737 legalTypes
, 1, BGRA_OR_4
,
738 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
743 * GL_EXT_gpu_shader4 / GL 3.0.
744 * Set an integer-valued vertex attribute array.
745 * Note that these arrays DO NOT alias the conventional GL vertex arrays
746 * (position, normal, color, fog, texcoord, etc).
749 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
750 GLsizei stride
, const GLvoid
*ptr
)
752 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
753 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
754 INT_BIT
| UNSIGNED_INT_BIT
);
755 const GLboolean normalized
= GL_FALSE
;
756 const GLboolean integer
= GL_TRUE
;
757 GET_CURRENT_CONTEXT(ctx
);
759 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
760 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
764 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
766 size
, type
, stride
, normalized
, integer
, GL_FALSE
, ptr
);
770 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
771 GLsizei stride
, const GLvoid
*ptr
)
773 GET_CURRENT_CONTEXT(ctx
);
774 const GLbitfield legalTypes
= (DOUBLE_BIT
);
775 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
776 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
780 update_array(ctx
, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index
),
782 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
787 _mesa_enable_vertex_array_attrib(struct gl_context
*ctx
,
788 struct gl_vertex_array_object
*vao
,
791 assert(attrib
< ARRAY_SIZE(vao
->VertexAttrib
));
793 if (!vao
->VertexAttrib
[attrib
].Enabled
) {
794 /* was disabled, now being enabled */
795 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
796 vao
->VertexAttrib
[attrib
].Enabled
= GL_TRUE
;
797 vao
->_Enabled
|= VERT_BIT(attrib
);
798 vao
->NewArrays
|= VERT_BIT(attrib
);
803 enable_vertex_array_attrib(struct gl_context
*ctx
,
804 struct gl_vertex_array_object
*vao
,
808 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
809 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
813 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
818 _mesa_EnableVertexAttribArray(GLuint index
)
820 GET_CURRENT_CONTEXT(ctx
);
821 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
822 "glEnableVertexAttribArray");
827 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
829 GET_CURRENT_CONTEXT(ctx
);
830 struct gl_vertex_array_object
*vao
;
832 /* The ARB_direct_state_access specification says:
834 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
835 * and DisableVertexArrayAttrib if <vaobj> is not
836 * [compatibility profile: zero or] the name of an existing vertex
839 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
843 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
848 disable_vertex_array_attrib(struct gl_context
*ctx
,
849 struct gl_vertex_array_object
*vao
,
853 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
854 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
858 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
860 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
861 /* was enabled, now being disabled */
862 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
863 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
864 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
865 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
871 _mesa_DisableVertexAttribArray(GLuint index
)
873 GET_CURRENT_CONTEXT(ctx
);
874 disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
875 "glDisableVertexAttribArray");
880 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
882 GET_CURRENT_CONTEXT(ctx
);
883 struct gl_vertex_array_object
*vao
;
885 /* The ARB_direct_state_access specification says:
887 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
888 * and DisableVertexArrayAttrib if <vaobj> is not
889 * [compatibility profile: zero or] the name of an existing vertex
892 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
896 disable_vertex_array_attrib(ctx
, vao
, index
, "glDisableVertexArrayAttrib");
901 * Return info for a vertex attribute array (no alias with legacy
902 * vertex attributes (pos, normal, color, etc)). This function does
903 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
906 get_vertex_array_attrib(struct gl_context
*ctx
,
907 const struct gl_vertex_array_object
*vao
,
908 GLuint index
, GLenum pname
,
911 const struct gl_array_attributes
*array
;
913 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
914 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
918 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
920 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
923 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
924 return array
->Enabled
;
925 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
926 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
927 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
928 return array
->Stride
;
929 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
931 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
932 return array
->Normalized
;
933 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
934 return vao
->VertexBinding
[array
->BufferBindingIndex
].BufferObj
->Name
;
935 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
936 if ((_mesa_is_desktop_gl(ctx
)
937 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
938 || _mesa_is_gles3(ctx
)) {
939 return array
->Integer
;
942 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
943 if (_mesa_is_desktop_gl(ctx
)) {
944 return array
->Doubles
;
947 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
948 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
949 || _mesa_is_gles3(ctx
)) {
950 return vao
->VertexBinding
[array
->BufferBindingIndex
].InstanceDivisor
;
953 case GL_VERTEX_ATTRIB_BINDING
:
954 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
955 return array
->BufferBindingIndex
- VERT_ATTRIB_GENERIC0
;
958 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
959 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
960 return array
->RelativeOffset
;
968 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
973 static const GLfloat
*
974 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
977 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
978 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
982 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
983 _mesa_error(ctx
, GL_INVALID_VALUE
,
984 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
988 assert(VERT_ATTRIB_GENERIC(index
) <
989 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
991 FLUSH_CURRENT(ctx
, 0);
992 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
996 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
998 GET_CURRENT_CONTEXT(ctx
);
1000 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1001 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
1007 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1009 "glGetVertexAttribfv");
1015 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1017 GET_CURRENT_CONTEXT(ctx
);
1019 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1020 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
1022 params
[0] = (GLdouble
) v
[0];
1023 params
[1] = (GLdouble
) v
[1];
1024 params
[2] = (GLdouble
) v
[2];
1025 params
[3] = (GLdouble
) v
[3];
1029 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1031 "glGetVertexAttribdv");
1036 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1038 GET_CURRENT_CONTEXT(ctx
);
1040 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1042 (const GLdouble
*)get_current_attrib(ctx
, index
,
1043 "glGetVertexAttribLdv");
1052 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1054 "glGetVertexAttribLdv");
1059 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
1061 GET_CURRENT_CONTEXT(ctx
);
1063 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1064 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1066 /* XXX should floats in[0,1] be scaled to full int range? */
1067 params
[0] = (GLint
) v
[0];
1068 params
[1] = (GLint
) v
[1];
1069 params
[2] = (GLint
) v
[2];
1070 params
[3] = (GLint
) v
[3];
1074 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1076 "glGetVertexAttribiv");
1083 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1085 GET_CURRENT_CONTEXT(ctx
);
1087 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1088 const GLint
*v
= (const GLint
*)
1089 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1095 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1097 "glGetVertexAttribIiv");
1104 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1106 GET_CURRENT_CONTEXT(ctx
);
1108 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1109 const GLuint
*v
= (const GLuint
*)
1110 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1116 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1118 "glGetVertexAttribIuiv");
1124 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1126 GET_CURRENT_CONTEXT(ctx
);
1128 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1129 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1133 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1134 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1138 assert(VERT_ATTRIB_GENERIC(index
) <
1139 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1141 *pointer
= (GLvoid
*)
1142 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1146 /** ARB_direct_state_access */
1148 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
1149 GLenum pname
, GLint
*params
)
1151 GET_CURRENT_CONTEXT(ctx
);
1152 struct gl_vertex_array_object
*vao
;
1154 /* The ARB_direct_state_access specification says:
1156 * "An INVALID_OPERATION error is generated if <vaobj> is not
1157 * [compatibility profile: zero or] the name of an existing
1158 * vertex array object."
1160 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexediv");
1164 /* The ARB_direct_state_access specification says:
1166 * "For GetVertexArrayIndexediv, <pname> must be one of
1167 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1168 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1169 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1170 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1171 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1175 * "Add GetVertexArrayIndexediv in 'Get Command' for
1176 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1177 * VERTEX_ATTRIB_BINDING,
1178 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1179 * VERTEX_BINDING_OFFSET, and
1180 * VERTEX_BINDING_STRIDE states"
1182 * The only parameter name common to both lists is
1183 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1184 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1185 * pretty clear however that the intent is that it should be possible
1186 * to query all vertex attrib and binding states that can be set with
1190 case GL_VERTEX_BINDING_OFFSET
:
1191 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1193 case GL_VERTEX_BINDING_STRIDE
:
1194 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
1196 case GL_VERTEX_BINDING_DIVISOR
:
1197 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
1199 case GL_VERTEX_BINDING_BUFFER
:
1200 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
1203 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
1204 "glGetVertexArrayIndexediv");
1211 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
1212 GLenum pname
, GLint64
*params
)
1214 GET_CURRENT_CONTEXT(ctx
);
1215 struct gl_vertex_array_object
*vao
;
1217 /* The ARB_direct_state_access specification says:
1219 * "An INVALID_OPERATION error is generated if <vaobj> is not
1220 * [compatibility profile: zero or] the name of an existing
1221 * vertex array object."
1223 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexed64iv");
1227 /* The ARB_direct_state_access specification says:
1229 * "For GetVertexArrayIndexed64iv, <pname> must be
1230 * VERTEX_BINDING_OFFSET."
1234 * "An INVALID_ENUM error is generated if <pname> is not one of
1235 * the valid values listed above for the corresponding command."
1237 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
1238 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
1239 "pname != GL_VERTEX_BINDING_OFFSET)");
1243 /* The ARB_direct_state_access specification says:
1245 * "An INVALID_VALUE error is generated if <index> is greater than
1246 * or equal to the value of MAX_VERTEX_ATTRIBS."
1248 * Since the index refers to a buffer binding in this case, the intended
1249 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1250 * required to be the same, so in practice this doesn't matter.
1252 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
1253 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
1254 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1255 index
, ctx
->Const
.MaxVertexAttribBindings
);
1259 params
[0] = vao
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1264 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1265 GLsizei count
, const GLvoid
*ptr
)
1268 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1273 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1277 _mesa_NormalPointer(type
, stride
, ptr
);
1282 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1286 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1291 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1295 _mesa_IndexPointer(type
, stride
, ptr
);
1300 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1301 GLsizei count
, const GLvoid
*ptr
)
1304 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1309 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1312 _mesa_EdgeFlagPointer(stride
, ptr
);
1317 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1319 GET_CURRENT_CONTEXT(ctx
);
1320 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1321 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1322 GLenum ctype
= 0; /* color type */
1323 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1324 const GLint toffset
= 0; /* always zero */
1325 GLint defstride
; /* default stride */
1328 FLUSH_VERTICES(ctx
, 0);
1330 f
= sizeof(GLfloat
);
1331 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1334 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1340 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1341 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1346 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1347 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1352 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1353 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1354 ctype
= GL_UNSIGNED_BYTE
;
1357 defstride
= c
+ 2*f
;
1360 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1361 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1362 ctype
= GL_UNSIGNED_BYTE
;
1365 defstride
= c
+ 3*f
;
1368 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1369 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1376 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1377 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1382 case GL_C4F_N3F_V3F
:
1383 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1384 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1392 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1393 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1398 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1399 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1403 case GL_T2F_C4UB_V3F
:
1404 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1405 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1406 ctype
= GL_UNSIGNED_BYTE
;
1411 case GL_T2F_C3F_V3F
:
1412 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1413 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1419 case GL_T2F_N3F_V3F
:
1420 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1421 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1426 case GL_T2F_C4F_N3F_V3F
:
1427 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1428 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1435 case GL_T4F_C4F_N3F_V4F
:
1436 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1437 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1445 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1453 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1454 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1455 /* XXX also disable secondary color and generic arrays? */
1459 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1460 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1461 (GLubyte
*) pointer
+ toffset
);
1464 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1469 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1470 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1471 (GLubyte
*) pointer
+ coffset
);
1474 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1480 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1481 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1484 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1488 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1489 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1490 (GLubyte
*) pointer
+ voffset
);
1495 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1497 GET_CURRENT_CONTEXT(ctx
);
1499 FLUSH_VERTICES(ctx
, 0);
1501 if (MESA_VERBOSE
& VERBOSE_API
)
1502 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1505 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1509 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1512 if (ctx
->Array
.LockCount
!= 0) {
1513 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1517 ctx
->Array
.LockFirst
= first
;
1518 ctx
->Array
.LockCount
= count
;
1520 ctx
->NewState
|= _NEW_ARRAY
;
1525 _mesa_UnlockArraysEXT( void )
1527 GET_CURRENT_CONTEXT(ctx
);
1529 FLUSH_VERTICES(ctx
, 0);
1531 if (MESA_VERBOSE
& VERBOSE_API
)
1532 _mesa_debug(ctx
, "glUnlockArrays\n");
1534 if (ctx
->Array
.LockCount
== 0) {
1535 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1539 ctx
->Array
.LockFirst
= 0;
1540 ctx
->Array
.LockCount
= 0;
1541 ctx
->NewState
|= _NEW_ARRAY
;
1545 /* GL_EXT_multi_draw_arrays */
1547 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1548 const GLsizei
*count
, GLsizei primcount
)
1550 GET_CURRENT_CONTEXT(ctx
);
1553 FLUSH_VERTICES(ctx
, 0);
1555 for (i
= 0; i
< primcount
; i
++) {
1557 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1563 /* GL_IBM_multimode_draw_arrays */
1565 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1566 const GLsizei
* count
,
1567 GLsizei primcount
, GLint modestride
)
1569 GET_CURRENT_CONTEXT(ctx
);
1572 FLUSH_VERTICES(ctx
, 0);
1574 for ( i
= 0 ; i
< primcount
; i
++ ) {
1575 if ( count
[i
] > 0 ) {
1576 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1577 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1583 /* GL_IBM_multimode_draw_arrays */
1585 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1586 GLenum type
, const GLvoid
* const * indices
,
1587 GLsizei primcount
, GLint modestride
)
1589 GET_CURRENT_CONTEXT(ctx
);
1592 FLUSH_VERTICES(ctx
, 0);
1594 /* XXX not sure about ARB_vertex_buffer_object handling here */
1596 for ( i
= 0 ; i
< primcount
; i
++ ) {
1597 if ( count
[i
] > 0 ) {
1598 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1599 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1607 * GL_NV_primitive_restart and GL 3.1
1610 _mesa_PrimitiveRestartIndex(GLuint index
)
1612 GET_CURRENT_CONTEXT(ctx
);
1614 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1615 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1619 if (ctx
->Array
.RestartIndex
!= index
) {
1620 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1621 ctx
->Array
.RestartIndex
= index
;
1627 * See GL_ARB_instanced_arrays.
1628 * Note that the instance divisor only applies to generic arrays, not
1629 * the legacy vertex arrays.
1632 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1634 GET_CURRENT_CONTEXT(ctx
);
1636 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1637 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1639 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1640 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1644 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1645 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1650 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
1652 /* The ARB_vertex_attrib_binding spec says:
1656 * void VertexAttribDivisor(uint index, uint divisor);
1658 * is equivalent to (assuming no errors are generated):
1660 * VertexAttribBinding(index, index);
1661 * VertexBindingDivisor(index, divisor);"
1663 vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
1664 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
1669 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1671 /* From the OpenGL 4.3 core specification, page 302:
1672 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1673 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1676 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1678 case GL_UNSIGNED_BYTE
:
1680 case GL_UNSIGNED_SHORT
:
1682 case GL_UNSIGNED_INT
:
1685 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1689 return ctx
->Array
.RestartIndex
;
1694 * GL_ARB_vertex_attrib_binding
1697 vertex_array_vertex_buffer(struct gl_context
*ctx
,
1698 struct gl_vertex_array_object
*vao
,
1699 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1700 GLsizei stride
, const char *func
)
1702 struct gl_buffer_object
*vbo
;
1704 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1706 /* The ARB_vertex_attrib_binding spec says:
1708 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1709 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1711 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1712 _mesa_error(ctx
, GL_INVALID_VALUE
,
1713 "%s(bindingindex=%u > "
1714 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1715 func
, bindingIndex
);
1719 /* The ARB_vertex_attrib_binding spec says:
1721 * "The error INVALID_VALUE is generated if <stride> or <offset>
1725 _mesa_error(ctx
, GL_INVALID_VALUE
,
1726 "%s(offset=%" PRId64
" < 0)",
1727 func
, (int64_t) offset
);
1732 _mesa_error(ctx
, GL_INVALID_VALUE
,
1733 "%s(stride=%d < 0)", func
, stride
);
1737 if (((ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
1738 stride
> ctx
->Const
.MaxVertexAttribStride
) {
1739 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
1740 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
1745 vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1746 vbo
= vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1747 } else if (buffer
!= 0) {
1748 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1750 if (!vbo
&& _mesa_is_gles31(ctx
)) {
1751 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", func
);
1754 /* From the GL_ARB_vertex_attrib_array spec:
1756 * "[Core profile only:]
1757 * An INVALID_OPERATION error is generated if buffer is not zero or a
1758 * name returned from a previous call to GenBuffers, or if such a name
1759 * has since been deleted with DeleteBuffers.
1761 * Otherwise, we fall back to the same compat profile behavior as other
1762 * object references (automatically gen it).
1764 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
1767 /* The ARB_vertex_attrib_binding spec says:
1769 * "If <buffer> is zero, any buffer object attached to this
1770 * bindpoint is detached."
1772 vbo
= ctx
->Shared
->NullBufferObj
;
1775 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
1776 vbo
, offset
, stride
);
1781 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1784 GET_CURRENT_CONTEXT(ctx
);
1786 /* The ARB_vertex_attrib_binding spec says:
1788 * "An INVALID_OPERATION error is generated if no vertex array object
1791 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
1792 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1793 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1794 "glBindVertexBuffer(No array object bound)");
1798 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
1799 buffer
, offset
, stride
, "glBindVertexBuffer");
1804 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
1805 GLintptr offset
, GLsizei stride
)
1807 GET_CURRENT_CONTEXT(ctx
);
1808 struct gl_vertex_array_object
*vao
;
1810 /* The ARB_direct_state_access specification says:
1812 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1813 * if <vaobj> is not [compatibility profile: zero or] the name of an
1814 * existing vertex array object."
1816 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
1820 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
,
1821 buffer
, offset
, stride
,
1822 "glVertexArrayVertexBuffer");
1827 vertex_array_vertex_buffers(struct gl_context
*ctx
,
1828 struct gl_vertex_array_object
*vao
,
1829 GLuint first
, GLsizei count
, const GLuint
*buffers
,
1830 const GLintptr
*offsets
, const GLsizei
*strides
,
1835 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1837 /* The ARB_multi_bind spec says:
1839 * "An INVALID_OPERATION error is generated if <first> + <count>
1840 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1842 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1843 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1844 "%s(first=%u + count=%d > the value of "
1845 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1846 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1852 * The ARB_multi_bind spec says:
1854 * "If <buffers> is NULL, each affected vertex buffer binding point
1855 * from <first> through <first>+<count>-1 will be reset to have no
1856 * bound buffer object. In this case, the offsets and strides
1857 * associated with the binding points are set to default values,
1858 * ignoring <offsets> and <strides>."
1860 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1862 for (i
= 0; i
< count
; i
++)
1863 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1869 /* Note that the error semantics for multi-bind commands differ from
1870 * those of other GL commands.
1872 * The Issues section in the ARB_multi_bind spec says:
1874 * "(11) Typically, OpenGL specifies that if an error is generated by
1875 * a command, that command has no effect. This is somewhat
1876 * unfortunate for multi-bind commands, because it would require
1877 * a first pass to scan the entire list of bound objects for
1878 * errors and then a second pass to actually perform the
1879 * bindings. Should we have different error semantics?
1881 * RESOLVED: Yes. In this specification, when the parameters for
1882 * one of the <count> binding points are invalid, that binding
1883 * point is not updated and an error will be generated. However,
1884 * other binding points in the same command will be updated if
1885 * their parameters are valid and no other error occurs."
1888 _mesa_begin_bufferobj_lookups(ctx
);
1890 for (i
= 0; i
< count
; i
++) {
1891 struct gl_buffer_object
*vbo
;
1893 /* The ARB_multi_bind spec says:
1895 * "An INVALID_VALUE error is generated if any value in
1896 * <offsets> or <strides> is negative (per binding)."
1898 if (offsets
[i
] < 0) {
1899 _mesa_error(ctx
, GL_INVALID_VALUE
,
1900 "%s(offsets[%u]=%" PRId64
" < 0)",
1901 func
, i
, (int64_t) offsets
[i
]);
1905 if (strides
[i
] < 0) {
1906 _mesa_error(ctx
, GL_INVALID_VALUE
,
1907 "%s(strides[%u]=%d < 0)",
1908 func
, i
, strides
[i
]);
1912 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1913 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
1914 _mesa_error(ctx
, GL_INVALID_VALUE
,
1915 "%s(strides[%u]=%d > "
1916 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
1921 struct gl_vertex_buffer_binding
*binding
=
1922 &vao
->VertexBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1924 if (buffers
[i
] == binding
->BufferObj
->Name
)
1925 vbo
= binding
->BufferObj
;
1927 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
1932 vbo
= ctx
->Shared
->NullBufferObj
;
1935 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1936 vbo
, offsets
[i
], strides
[i
]);
1939 _mesa_end_bufferobj_lookups(ctx
);
1944 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1945 const GLintptr
*offsets
, const GLsizei
*strides
)
1947 GET_CURRENT_CONTEXT(ctx
);
1949 /* The ARB_vertex_attrib_binding spec says:
1951 * "An INVALID_OPERATION error is generated if no
1952 * vertex array object is bound."
1954 if (ctx
->API
== API_OPENGL_CORE
&&
1955 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1956 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1957 "glBindVertexBuffers(No array object bound)");
1961 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
1962 buffers
, offsets
, strides
,
1963 "glBindVertexBuffers");
1968 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
1969 const GLuint
*buffers
,
1970 const GLintptr
*offsets
, const GLsizei
*strides
)
1972 GET_CURRENT_CONTEXT(ctx
);
1973 struct gl_vertex_array_object
*vao
;
1975 /* The ARB_direct_state_access specification says:
1977 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1978 * if <vaobj> is not [compatibility profile: zero or] the name of an
1979 * existing vertex array object."
1981 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
1985 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
1986 buffers
, offsets
, strides
,
1987 "glVertexArrayVertexBuffers");
1992 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
1993 GLboolean normalized
, GLboolean integer
,
1994 GLboolean doubles
, GLbitfield legalTypes
,
1995 GLsizei maxSize
, GLuint relativeOffset
,
1998 GET_CURRENT_CONTEXT(ctx
);
1999 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2001 /* The ARB_vertex_attrib_binding spec says:
2003 * "An INVALID_OPERATION error is generated under any of the following
2005 * - if no vertex array object is currently bound (see section 2.10);
2008 * This error condition only applies to VertexAttribFormat and
2009 * VertexAttribIFormat in the extension spec, but we assume that this
2010 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2011 * to all three functions.
2013 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2014 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2015 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2016 "%s(No array object bound)", func
);
2020 /* The ARB_vertex_attrib_binding spec says:
2022 * "The error INVALID_VALUE is generated if index is greater than or equal
2023 * to the value of MAX_VERTEX_ATTRIBS."
2025 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2026 _mesa_error(ctx
, GL_INVALID_VALUE
,
2027 "%s(attribindex=%u > "
2028 "GL_MAX_VERTEX_ATTRIBS)",
2033 FLUSH_VERTICES(ctx
, 0);
2035 update_array_format(ctx
, func
, ctx
->Array
.VAO
,
2036 VERT_ATTRIB_GENERIC(attribIndex
),
2037 legalTypes
, 1, maxSize
, size
, type
,
2038 normalized
, integer
, doubles
, relativeOffset
);
2043 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2044 GLboolean normalized
, GLuint relativeOffset
)
2046 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
2047 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2048 BGRA_OR_4
, relativeOffset
,
2049 "glVertexAttribFormat");
2054 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2055 GLuint relativeOffset
)
2057 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
2058 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
2059 relativeOffset
, "glVertexAttribIFormat");
2064 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2065 GLuint relativeOffset
)
2067 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
2068 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
2069 relativeOffset
, "glVertexAttribLFormat");
2074 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2075 GLenum type
, GLboolean normalized
,
2076 GLboolean integer
, GLboolean doubles
,
2077 GLbitfield legalTypes
, GLsizei maxSize
,
2078 GLuint relativeOffset
, const char *func
)
2080 GET_CURRENT_CONTEXT(ctx
);
2081 struct gl_vertex_array_object
*vao
;
2083 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2085 /* The ARB_direct_state_access spec says:
2087 * "An INVALID_OPERATION error is generated by VertexArrayAttrib*Format
2088 * if <vaobj> is not [compatibility profile: zero or] the name of an
2089 * existing vertex array object."
2091 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
2095 /* The ARB_vertex_attrib_binding spec says:
2097 * "The error INVALID_VALUE is generated if index is greater than or equal
2098 * to the value of MAX_VERTEX_ATTRIBS."
2100 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2101 _mesa_error(ctx
, GL_INVALID_VALUE
,
2102 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2107 FLUSH_VERTICES(ctx
, 0);
2109 update_array_format(ctx
, func
, vao
,
2110 VERT_ATTRIB_GENERIC(attribIndex
),
2111 legalTypes
, 1, maxSize
, size
, type
, normalized
,
2112 integer
, doubles
, relativeOffset
);
2117 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2118 GLenum type
, GLboolean normalized
,
2119 GLuint relativeOffset
)
2121 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
2122 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2123 BGRA_OR_4
, relativeOffset
,
2124 "glVertexArrayAttribFormat");
2129 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
2130 GLint size
, GLenum type
,
2131 GLuint relativeOffset
)
2133 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2134 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
2136 "glVertexArrayAttribIFormat");
2141 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
2142 GLint size
, GLenum type
,
2143 GLuint relativeOffset
)
2145 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2146 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
2148 "glVertexArrayAttribLFormat");
2153 vertex_array_attrib_binding(struct gl_context
*ctx
,
2154 struct gl_vertex_array_object
*vao
,
2155 GLuint attribIndex
, GLuint bindingIndex
,
2158 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2160 /* The ARB_vertex_attrib_binding spec says:
2162 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2163 * <bindingindex> must be less than the value of
2164 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2167 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2168 _mesa_error(ctx
, GL_INVALID_VALUE
,
2169 "%s(attribindex=%u >= "
2170 "GL_MAX_VERTEX_ATTRIBS)",
2175 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2176 _mesa_error(ctx
, GL_INVALID_VALUE
,
2177 "%s(bindingindex=%u >= "
2178 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2179 func
, bindingIndex
);
2183 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
2185 vertex_attrib_binding(ctx
, vao
,
2186 VERT_ATTRIB_GENERIC(attribIndex
),
2187 VERT_ATTRIB_GENERIC(bindingIndex
));
2192 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2194 GET_CURRENT_CONTEXT(ctx
);
2196 /* The ARB_vertex_attrib_binding spec says:
2198 * "An INVALID_OPERATION error is generated if no vertex array object
2201 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2202 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2203 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2204 "glVertexAttribBinding(No array object bound)");
2208 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2209 attribIndex
, bindingIndex
,
2210 "glVertexAttribBinding");
2215 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2217 GET_CURRENT_CONTEXT(ctx
);
2218 struct gl_vertex_array_object
*vao
;
2220 /* The ARB_direct_state_access specification says:
2222 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2223 * if <vaobj> is not [compatibility profile: zero or] the name of an
2224 * existing vertex array object."
2226 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2230 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2231 "glVertexArrayAttribBinding");
2236 vertex_array_binding_divisor(struct gl_context
*ctx
,
2237 struct gl_vertex_array_object
*vao
,
2238 GLuint bindingIndex
, GLuint divisor
,
2241 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2243 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2244 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
2248 /* The ARB_vertex_attrib_binding spec says:
2250 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2251 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2253 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2254 _mesa_error(ctx
, GL_INVALID_VALUE
,
2255 "%s(bindingindex=%u > "
2256 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2257 func
, bindingIndex
);
2261 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2266 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2268 GET_CURRENT_CONTEXT(ctx
);
2270 /* The ARB_vertex_attrib_binding spec says:
2272 * "An INVALID_OPERATION error is generated if no vertex array object
2275 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2276 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2277 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2278 "glVertexBindingDivisor(No array object bound)");
2282 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
2283 bindingIndex
, divisor
,
2284 "glVertexBindingDivisor");
2289 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
2292 struct gl_vertex_array_object
*vao
;
2293 GET_CURRENT_CONTEXT(ctx
);
2295 /* The ARB_direct_state_access specification says:
2297 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2298 * if <vaobj> is not [compatibility profile: zero or] the name of an
2299 * existing vertex array object."
2301 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayBindingDivisor");
2305 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
2306 "glVertexArrayBindingDivisor");
2311 * Copy one client vertex array to another.
2314 _mesa_copy_client_array(struct gl_context
*ctx
,
2315 struct gl_client_array
*dst
,
2316 struct gl_client_array
*src
)
2318 dst
->Size
= src
->Size
;
2319 dst
->Type
= src
->Type
;
2320 dst
->Format
= src
->Format
;
2321 dst
->StrideB
= src
->StrideB
;
2322 dst
->Ptr
= src
->Ptr
;
2323 dst
->Normalized
= src
->Normalized
;
2324 dst
->Integer
= src
->Integer
;
2325 dst
->Doubles
= src
->Doubles
;
2326 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2327 dst
->_ElementSize
= src
->_ElementSize
;
2328 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2332 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2333 struct gl_array_attributes
*dst
,
2334 const struct gl_array_attributes
*src
)
2336 dst
->Size
= src
->Size
;
2337 dst
->Type
= src
->Type
;
2338 dst
->Format
= src
->Format
;
2339 dst
->BufferBindingIndex
= src
->BufferBindingIndex
;
2340 dst
->RelativeOffset
= src
->RelativeOffset
;
2341 dst
->Format
= src
->Format
;
2342 dst
->Integer
= src
->Integer
;
2343 dst
->Doubles
= src
->Doubles
;
2344 dst
->Normalized
= src
->Normalized
;
2345 dst
->Ptr
= src
->Ptr
;
2346 dst
->Enabled
= src
->Enabled
;
2347 dst
->_ElementSize
= src
->_ElementSize
;
2351 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2352 struct gl_vertex_buffer_binding
*dst
,
2353 const struct gl_vertex_buffer_binding
*src
)
2355 dst
->Offset
= src
->Offset
;
2356 dst
->Stride
= src
->Stride
;
2357 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2358 dst
->_BoundArrays
= src
->_BoundArrays
;
2360 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2364 * Print current vertex object/array info. For debug.
2367 _mesa_print_arrays(struct gl_context
*ctx
)
2369 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2371 fprintf(stderr
, "Array Object %u\n", vao
->Name
);
2374 for (i
= 0; i
< VERT_ATTRIB_MAX
; ++i
) {
2375 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
2376 if (!array
->Enabled
)
2379 const struct gl_vertex_buffer_binding
*binding
=
2380 &vao
->VertexBinding
[array
->BufferBindingIndex
];
2381 const struct gl_buffer_object
*bo
= binding
->BufferObj
;
2383 fprintf(stderr
, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
2384 "Stride=%d, Buffer=%u(Size %lu)\n",
2385 gl_vert_attrib_name((gl_vert_attrib
)i
),
2386 array
->Ptr
, _mesa_enum_to_string(array
->Type
), array
->Size
,
2387 array
->_ElementSize
, binding
->Stride
, bo
->Name
,
2388 (unsigned long) bo
->Size
);
2394 * Initialize vertex array state for given context.
2397 _mesa_init_varray(struct gl_context
*ctx
)
2399 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
2400 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2401 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2403 ctx
->Array
.Objects
= _mesa_NewHashTable();
2408 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2411 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2413 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2414 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2415 _mesa_delete_vao(ctx
, vao
);
2420 * Free vertex array state for given context.
2423 _mesa_free_varray_data(struct gl_context
*ctx
)
2425 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2426 _mesa_DeleteHashTable(ctx
->Array
.Objects
);