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 case GL_HALF_FLOAT_OES
:
106 if (ctx
->Extensions
.ARB_half_float_vertex
)
115 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
116 case GL_UNSIGNED_INT_2_10_10_10_REV
:
117 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
118 case GL_INT_2_10_10_10_REV
:
119 return INT_2_10_10_10_REV_BIT
;
120 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
121 return UNSIGNED_INT_10F_11F_11F_REV_BIT
;
129 * Sets the BufferBindingIndex field for the vertex attribute given by
133 vertex_attrib_binding(struct gl_context
*ctx
,
134 struct gl_vertex_array_object
*vao
,
138 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attribIndex
];
140 if (!_mesa_is_bufferobj(vao
->BufferBinding
[bindingIndex
].BufferObj
))
141 vao
->VertexAttribBufferMask
&= ~VERT_BIT(attribIndex
);
143 vao
->VertexAttribBufferMask
|= VERT_BIT(attribIndex
);
145 if (array
->BufferBindingIndex
!= bindingIndex
) {
146 const GLbitfield64 array_bit
= VERT_BIT(attribIndex
);
148 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
150 vao
->BufferBinding
[array
->BufferBindingIndex
]._BoundArrays
&= ~array_bit
;
151 vao
->BufferBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
153 array
->BufferBindingIndex
= bindingIndex
;
155 vao
->NewArrays
|= array_bit
;
161 * Binds a buffer object to the vertex buffer binding point given by index,
162 * and sets the Offset and Stride fields.
165 _mesa_bind_vertex_buffer(struct gl_context
*ctx
,
166 struct gl_vertex_array_object
*vao
,
168 struct gl_buffer_object
*vbo
,
169 GLintptr offset
, GLsizei stride
)
171 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
173 if (binding
->BufferObj
!= vbo
||
174 binding
->Offset
!= offset
||
175 binding
->Stride
!= stride
) {
177 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
179 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
181 binding
->Offset
= offset
;
182 binding
->Stride
= stride
;
184 if (!_mesa_is_bufferobj(vbo
))
185 vao
->VertexAttribBufferMask
&= ~binding
->_BoundArrays
;
187 vao
->VertexAttribBufferMask
|= binding
->_BoundArrays
;
189 vao
->NewArrays
|= binding
->_BoundArrays
;
195 * Sets the InstanceDivisor field in the vertex buffer binding point
196 * given by bindingIndex.
199 vertex_binding_divisor(struct gl_context
*ctx
,
200 struct gl_vertex_array_object
*vao
,
204 struct gl_vertex_buffer_binding
*binding
=
205 &vao
->BufferBinding
[bindingIndex
];
207 if (binding
->InstanceDivisor
!= divisor
) {
208 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
209 binding
->InstanceDivisor
= divisor
;
210 vao
->NewArrays
|= binding
->_BoundArrays
;
216 * Examine the API profile and extensions to determine which types are legal
217 * for vertex arrays. This is called once from update_array_format().
220 get_legal_types_mask(const struct gl_context
*ctx
)
222 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
224 if (_mesa_is_gles(ctx
)) {
225 legalTypesMask
&= ~(FIXED_GL_BIT
|
227 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
229 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
230 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
231 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
232 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
233 * quite as trivial as we'd like because it uses a different enum value
234 * for GL_HALF_FLOAT_OES.
236 if (ctx
->Version
< 30) {
237 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
239 UNSIGNED_INT_2_10_10_10_REV_BIT
|
240 INT_2_10_10_10_REV_BIT
);
242 if (!_mesa_has_OES_vertex_half_float(ctx
))
243 legalTypesMask
&= ~HALF_BIT
;
247 legalTypesMask
&= ~FIXED_ES_BIT
;
249 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
250 legalTypesMask
&= ~FIXED_GL_BIT
;
252 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
253 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
254 INT_2_10_10_10_REV_BIT
);
256 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
257 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
260 return legalTypesMask
;
265 * \param attrib The index of the attribute array
266 * \param size Components per element (1, 2, 3 or 4)
267 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
268 * \param format Either GL_RGBA or GL_BGRA.
269 * \param normalized Whether integer types are converted to floats in [-1, 1]
270 * \param integer Integer-valued values (will not be normalized to [-1, 1])
271 * \param doubles Double values not reduced to floats
272 * \param relativeOffset Offset of the first element relative to the binding
274 * \param flush_verties Should \c FLUSH_VERTICES be invoked before updating
278 _mesa_update_array_format(struct gl_context
*ctx
,
279 struct gl_vertex_array_object
*vao
,
280 GLuint attrib
, GLint size
, GLenum type
,
281 GLenum format
, GLboolean normalized
,
282 GLboolean integer
, GLboolean doubles
,
283 GLuint relativeOffset
, bool flush_vertices
)
285 struct gl_array_attributes
*const array
= &vao
->VertexAttrib
[attrib
];
290 if (flush_vertices
) {
291 FLUSH_VERTICES(ctx
, 0);
294 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
295 assert(elementSize
!= -1);
299 array
->Format
= format
;
300 array
->Normalized
= normalized
;
301 array
->Integer
= integer
;
302 array
->Doubles
= doubles
;
303 array
->RelativeOffset
= relativeOffset
;
304 array
->_ElementSize
= elementSize
;
306 vao
->NewArrays
|= VERT_BIT(attrib
);
307 ctx
->NewState
|= _NEW_ARRAY
;
311 * Does error checking and updates the format in an attrib array.
313 * Called by update_array() and VertexAttrib*Format().
315 * \param func Name of calling function used for error reporting
316 * \param attrib The index of the attribute array
317 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
318 * \param sizeMin Min allowable size value
319 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
320 * \param size Components per element (1, 2, 3 or 4)
321 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
322 * \param normalized Whether integer types are converted to floats in [-1, 1]
323 * \param integer Integer-valued values (will not be normalized to [-1, 1])
324 * \param doubles Double values not reduced to floats
325 * \param relativeOffset Offset of the first element relative to the binding offset.
328 update_array_format(struct gl_context
*ctx
,
330 struct gl_vertex_array_object
*vao
,
331 GLuint attrib
, GLbitfield legalTypesMask
,
332 GLint sizeMin
, GLint sizeMax
,
333 GLint size
, GLenum type
,
334 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
335 GLuint relativeOffset
)
338 GLenum format
= GL_RGBA
;
340 /* at most, one of these bools can be true */
341 assert((int) normalized
+ (int) integer
+ (int) doubles
<= 1);
343 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
344 /* Compute the LegalTypesMask only once, unless the context API has
345 * changed, in which case we want to compute it again. We can't do this
346 * in _mesa_init_varrays() below because extensions are not yet enabled
349 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
350 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
353 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
355 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
356 /* BGRA ordering is not supported in ES contexts.
361 typeBit
= type_to_bit(ctx
, type
);
362 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
363 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
364 func
, _mesa_enum_to_string(type
));
368 /* Do size parameter checking.
369 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
370 * must be handled specially.
372 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
373 sizeMax
== BGRA_OR_4
&&
375 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
377 * "An INVALID_OPERATION error is generated under any of the following
380 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
381 * or UNSIGNED_INT_2_10_10_10_REV;
383 * • size is BGRA and normalized is FALSE;"
385 bool bgra_error
= false;
387 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
388 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
389 type
!= GL_INT_2_10_10_10_REV
&&
390 type
!= GL_UNSIGNED_BYTE
)
392 } else if (type
!= GL_UNSIGNED_BYTE
)
396 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
397 func
, _mesa_enum_to_string(type
));
402 _mesa_error(ctx
, GL_INVALID_OPERATION
,
403 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
410 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
411 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
415 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
416 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
417 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
418 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
422 /* The ARB_vertex_attrib_binding_spec says:
424 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
425 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
427 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
428 _mesa_error(ctx
, GL_INVALID_VALUE
,
429 "%s(relativeOffset=%d > "
430 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
431 func
, relativeOffset
);
435 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
436 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
437 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
441 _mesa_update_array_format(ctx
, vao
, attrib
, size
, type
, format
,
442 normalized
, integer
, doubles
, relativeOffset
,
450 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
453 * \param func name of calling function used for error reporting
454 * \param attrib the attribute array index to update
455 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
456 * \param sizeMin min allowable size value
457 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
458 * \param size components per element (1, 2, 3 or 4)
459 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
460 * \param stride stride between elements, in elements
461 * \param normalized are integer types converted to floats in [-1, 1]?
462 * \param integer integer-valued values (will not be normalized to [-1,1])
463 * \param doubles Double values not reduced to floats
464 * \param ptr the address (or offset inside VBO) of the array data
467 update_array(struct gl_context
*ctx
,
469 GLuint attrib
, GLbitfield legalTypesMask
,
470 GLint sizeMin
, GLint sizeMax
,
471 GLint size
, GLenum type
, GLsizei stride
,
472 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
475 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
476 struct gl_array_attributes
*array
;
477 GLsizei effectiveStride
;
479 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
481 * "Client vertex arrays - all vertex array attribute pointers must
482 * refer to buffer objects (section 2.9.2). The default vertex array
483 * object (the name zero) is also deprecated. Calling
484 * VertexAttribPointer when no buffer object or no vertex array object
485 * is bound will generate an INVALID_OPERATION error..."
487 * The check for VBOs is handled below.
489 if (ctx
->API
== API_OPENGL_CORE
&& (vao
== ctx
->Array
.DefaultVAO
)) {
490 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
496 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
500 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
501 stride
> ctx
->Const
.MaxVertexAttribStride
) {
502 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
503 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
507 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
509 * "An INVALID_OPERATION error is generated under any of the following
514 * * any of the *Pointer commands specifying the location and
515 * organization of vertex array data are called while zero is bound
516 * to the ARRAY_BUFFER buffer object binding point (see section
517 * 2.9.6), and the pointer argument is not NULL."
519 if (ptr
!= NULL
&& vao
->ARBsemantics
&&
520 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
521 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
525 if (!update_array_format(ctx
, func
, vao
, attrib
,
526 legalTypesMask
, sizeMin
, sizeMax
,
527 size
, type
, normalized
, integer
, doubles
, 0)) {
531 /* Reset the vertex attrib binding */
532 vertex_attrib_binding(ctx
, vao
, attrib
, attrib
);
534 /* The Stride and Ptr fields are not set by update_array_format() */
535 array
= &vao
->VertexAttrib
[attrib
];
536 array
->Stride
= stride
;
539 /* Update the vertex buffer binding */
540 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
541 _mesa_bind_vertex_buffer(ctx
, vao
, attrib
,
542 ctx
->Array
.ArrayBufferObj
, (GLintptr
) ptr
,
548 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
550 GET_CURRENT_CONTEXT(ctx
);
551 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
552 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
553 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
554 DOUBLE_BIT
| HALF_BIT
|
555 UNSIGNED_INT_2_10_10_10_REV_BIT
|
556 INT_2_10_10_10_REV_BIT
);
558 FLUSH_VERTICES(ctx
, 0);
560 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
562 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
567 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
569 GET_CURRENT_CONTEXT(ctx
);
570 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
571 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
572 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
573 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
574 UNSIGNED_INT_2_10_10_10_REV_BIT
|
575 INT_2_10_10_10_REV_BIT
);
577 FLUSH_VERTICES(ctx
, 0);
579 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
581 3, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
586 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
588 GET_CURRENT_CONTEXT(ctx
);
589 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
590 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
591 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
592 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
593 INT_BIT
| UNSIGNED_INT_BIT
|
594 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
595 UNSIGNED_INT_2_10_10_10_REV_BIT
|
596 INT_2_10_10_10_REV_BIT
);
597 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
599 FLUSH_VERTICES(ctx
, 0);
601 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
602 legalTypes
, sizeMin
, BGRA_OR_4
,
603 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
608 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
610 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
611 GET_CURRENT_CONTEXT(ctx
);
613 FLUSH_VERTICES(ctx
, 0);
615 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
617 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
622 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
624 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
625 FLOAT_BIT
| DOUBLE_BIT
);
626 GET_CURRENT_CONTEXT(ctx
);
628 FLUSH_VERTICES(ctx
, 0);
630 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
632 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
637 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
638 GLsizei stride
, const GLvoid
*ptr
)
640 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
641 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
642 INT_BIT
| UNSIGNED_INT_BIT
|
643 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
644 UNSIGNED_INT_2_10_10_10_REV_BIT
|
645 INT_2_10_10_10_REV_BIT
);
646 GET_CURRENT_CONTEXT(ctx
);
648 FLUSH_VERTICES(ctx
, 0);
650 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
651 legalTypes
, 3, BGRA_OR_4
,
652 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
657 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
660 GET_CURRENT_CONTEXT(ctx
);
661 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
662 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
663 : (SHORT_BIT
| INT_BIT
|
664 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
665 UNSIGNED_INT_2_10_10_10_REV_BIT
|
666 INT_2_10_10_10_REV_BIT
);
667 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
668 const GLuint unit
= ctx
->Array
.ActiveTexture
;
670 FLUSH_VERTICES(ctx
, 0);
672 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
673 legalTypes
, sizeMin
, 4,
674 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
680 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
682 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
683 /* this is the same type that glEdgeFlag uses */
684 const GLboolean integer
= GL_FALSE
;
685 GET_CURRENT_CONTEXT(ctx
);
687 FLUSH_VERTICES(ctx
, 0);
689 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
691 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
696 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
698 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
699 GET_CURRENT_CONTEXT(ctx
);
701 FLUSH_VERTICES(ctx
, 0);
703 if (ctx
->API
!= API_OPENGLES
) {
704 _mesa_error(ctx
, GL_INVALID_OPERATION
,
705 "glPointSizePointer(ES 1.x only)");
709 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
711 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
716 * Set a generic vertex attribute array.
717 * Note that these arrays DO NOT alias the conventional GL vertex arrays
718 * (position, normal, color, fog, texcoord, etc).
721 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
722 GLboolean normalized
,
723 GLsizei stride
, const GLvoid
*ptr
)
725 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
726 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
727 INT_BIT
| UNSIGNED_INT_BIT
|
728 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
729 FIXED_ES_BIT
| FIXED_GL_BIT
|
730 UNSIGNED_INT_2_10_10_10_REV_BIT
|
731 INT_2_10_10_10_REV_BIT
|
732 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
733 GET_CURRENT_CONTEXT(ctx
);
735 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
736 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
740 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
741 legalTypes
, 1, BGRA_OR_4
,
742 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
747 * GL_EXT_gpu_shader4 / GL 3.0.
748 * Set an integer-valued vertex attribute array.
749 * Note that these arrays DO NOT alias the conventional GL vertex arrays
750 * (position, normal, color, fog, texcoord, etc).
753 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
754 GLsizei stride
, const GLvoid
*ptr
)
756 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
757 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
758 INT_BIT
| UNSIGNED_INT_BIT
);
759 const GLboolean normalized
= GL_FALSE
;
760 const GLboolean integer
= GL_TRUE
;
761 GET_CURRENT_CONTEXT(ctx
);
763 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
764 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
768 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
770 size
, type
, stride
, normalized
, integer
, GL_FALSE
, ptr
);
774 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
775 GLsizei stride
, const GLvoid
*ptr
)
777 GET_CURRENT_CONTEXT(ctx
);
778 const GLbitfield legalTypes
= (DOUBLE_BIT
);
779 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
780 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
784 update_array(ctx
, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index
),
786 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
791 _mesa_enable_vertex_array_attrib(struct gl_context
*ctx
,
792 struct gl_vertex_array_object
*vao
,
795 assert(attrib
< ARRAY_SIZE(vao
->VertexAttrib
));
797 if (!vao
->VertexAttrib
[attrib
].Enabled
) {
798 /* was disabled, now being enabled */
799 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
800 vao
->VertexAttrib
[attrib
].Enabled
= GL_TRUE
;
801 vao
->_Enabled
|= VERT_BIT(attrib
);
802 vao
->NewArrays
|= VERT_BIT(attrib
);
807 enable_vertex_array_attrib(struct gl_context
*ctx
,
808 struct gl_vertex_array_object
*vao
,
812 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
813 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
817 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
822 _mesa_EnableVertexAttribArray(GLuint index
)
824 GET_CURRENT_CONTEXT(ctx
);
825 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
826 "glEnableVertexAttribArray");
831 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
833 GET_CURRENT_CONTEXT(ctx
);
834 struct gl_vertex_array_object
*vao
;
836 /* The ARB_direct_state_access specification says:
838 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
839 * and DisableVertexArrayAttrib if <vaobj> is not
840 * [compatibility profile: zero or] the name of an existing vertex
843 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
847 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
852 disable_vertex_array_attrib(struct gl_context
*ctx
,
853 struct gl_vertex_array_object
*vao
,
857 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
858 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
862 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
864 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
865 /* was enabled, now being disabled */
866 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
867 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
868 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
869 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
875 _mesa_DisableVertexAttribArray(GLuint index
)
877 GET_CURRENT_CONTEXT(ctx
);
878 disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
879 "glDisableVertexAttribArray");
884 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
886 GET_CURRENT_CONTEXT(ctx
);
887 struct gl_vertex_array_object
*vao
;
889 /* The ARB_direct_state_access specification says:
891 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
892 * and DisableVertexArrayAttrib if <vaobj> is not
893 * [compatibility profile: zero or] the name of an existing vertex
896 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
900 disable_vertex_array_attrib(ctx
, vao
, index
, "glDisableVertexArrayAttrib");
905 * Return info for a vertex attribute array (no alias with legacy
906 * vertex attributes (pos, normal, color, etc)). This function does
907 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
910 get_vertex_array_attrib(struct gl_context
*ctx
,
911 const struct gl_vertex_array_object
*vao
,
912 GLuint index
, GLenum pname
,
915 const struct gl_array_attributes
*array
;
917 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
918 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
922 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
924 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
927 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
928 return array
->Enabled
;
929 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
930 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
931 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
932 return array
->Stride
;
933 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
935 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
936 return array
->Normalized
;
937 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
938 return vao
->BufferBinding
[array
->BufferBindingIndex
].BufferObj
->Name
;
939 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
940 if ((_mesa_is_desktop_gl(ctx
)
941 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
942 || _mesa_is_gles3(ctx
)) {
943 return array
->Integer
;
946 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
947 if (_mesa_is_desktop_gl(ctx
)) {
948 return array
->Doubles
;
951 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
952 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
953 || _mesa_is_gles3(ctx
)) {
954 return vao
->BufferBinding
[array
->BufferBindingIndex
].InstanceDivisor
;
957 case GL_VERTEX_ATTRIB_BINDING
:
958 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
959 return array
->BufferBindingIndex
- VERT_ATTRIB_GENERIC0
;
962 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
963 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
964 return array
->RelativeOffset
;
972 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
977 static const GLfloat
*
978 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
981 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
982 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
986 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
987 _mesa_error(ctx
, GL_INVALID_VALUE
,
988 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
992 assert(VERT_ATTRIB_GENERIC(index
) <
993 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
995 FLUSH_CURRENT(ctx
, 0);
996 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
1000 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
1002 GET_CURRENT_CONTEXT(ctx
);
1004 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1005 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
1011 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1013 "glGetVertexAttribfv");
1019 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1021 GET_CURRENT_CONTEXT(ctx
);
1023 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1024 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
1026 params
[0] = (GLdouble
) v
[0];
1027 params
[1] = (GLdouble
) v
[1];
1028 params
[2] = (GLdouble
) v
[2];
1029 params
[3] = (GLdouble
) v
[3];
1033 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1035 "glGetVertexAttribdv");
1040 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1042 GET_CURRENT_CONTEXT(ctx
);
1044 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1046 (const GLdouble
*)get_current_attrib(ctx
, index
,
1047 "glGetVertexAttribLdv");
1056 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1058 "glGetVertexAttribLdv");
1063 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
1065 GET_CURRENT_CONTEXT(ctx
);
1067 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1068 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1070 /* XXX should floats in[0,1] be scaled to full int range? */
1071 params
[0] = (GLint
) v
[0];
1072 params
[1] = (GLint
) v
[1];
1073 params
[2] = (GLint
) v
[2];
1074 params
[3] = (GLint
) v
[3];
1078 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1080 "glGetVertexAttribiv");
1087 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1089 GET_CURRENT_CONTEXT(ctx
);
1091 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1092 const GLint
*v
= (const GLint
*)
1093 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1099 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1101 "glGetVertexAttribIiv");
1108 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1110 GET_CURRENT_CONTEXT(ctx
);
1112 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1113 const GLuint
*v
= (const GLuint
*)
1114 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1120 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1122 "glGetVertexAttribIuiv");
1128 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1130 GET_CURRENT_CONTEXT(ctx
);
1132 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1133 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1137 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1138 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1142 assert(VERT_ATTRIB_GENERIC(index
) <
1143 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1145 *pointer
= (GLvoid
*)
1146 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1150 /** ARB_direct_state_access */
1152 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
1153 GLenum pname
, GLint
*params
)
1155 GET_CURRENT_CONTEXT(ctx
);
1156 struct gl_vertex_array_object
*vao
;
1158 /* The ARB_direct_state_access specification says:
1160 * "An INVALID_OPERATION error is generated if <vaobj> is not
1161 * [compatibility profile: zero or] the name of an existing
1162 * vertex array object."
1164 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexediv");
1168 /* The ARB_direct_state_access specification says:
1170 * "For GetVertexArrayIndexediv, <pname> must be one of
1171 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1172 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1173 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1174 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1175 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1179 * "Add GetVertexArrayIndexediv in 'Get Command' for
1180 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1181 * VERTEX_ATTRIB_BINDING,
1182 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1183 * VERTEX_BINDING_OFFSET, and
1184 * VERTEX_BINDING_STRIDE states"
1186 * The only parameter name common to both lists is
1187 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1188 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1189 * pretty clear however that the intent is that it should be possible
1190 * to query all vertex attrib and binding states that can be set with
1194 case GL_VERTEX_BINDING_OFFSET
:
1195 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1197 case GL_VERTEX_BINDING_STRIDE
:
1198 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
1200 case GL_VERTEX_BINDING_DIVISOR
:
1201 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
1203 case GL_VERTEX_BINDING_BUFFER
:
1204 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
1207 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
1208 "glGetVertexArrayIndexediv");
1215 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
1216 GLenum pname
, GLint64
*params
)
1218 GET_CURRENT_CONTEXT(ctx
);
1219 struct gl_vertex_array_object
*vao
;
1221 /* The ARB_direct_state_access specification says:
1223 * "An INVALID_OPERATION error is generated if <vaobj> is not
1224 * [compatibility profile: zero or] the name of an existing
1225 * vertex array object."
1227 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexed64iv");
1231 /* The ARB_direct_state_access specification says:
1233 * "For GetVertexArrayIndexed64iv, <pname> must be
1234 * VERTEX_BINDING_OFFSET."
1238 * "An INVALID_ENUM error is generated if <pname> is not one of
1239 * the valid values listed above for the corresponding command."
1241 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
1242 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
1243 "pname != GL_VERTEX_BINDING_OFFSET)");
1247 /* The ARB_direct_state_access specification says:
1249 * "An INVALID_VALUE error is generated if <index> is greater than
1250 * or equal to the value of MAX_VERTEX_ATTRIBS."
1252 * Since the index refers to a buffer binding in this case, the intended
1253 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1254 * required to be the same, so in practice this doesn't matter.
1256 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
1257 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
1258 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1259 index
, ctx
->Const
.MaxVertexAttribBindings
);
1263 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1268 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1269 GLsizei count
, const GLvoid
*ptr
)
1272 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1277 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1281 _mesa_NormalPointer(type
, stride
, ptr
);
1286 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1290 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1295 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1299 _mesa_IndexPointer(type
, stride
, ptr
);
1304 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1305 GLsizei count
, const GLvoid
*ptr
)
1308 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1313 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1316 _mesa_EdgeFlagPointer(stride
, ptr
);
1321 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1323 GET_CURRENT_CONTEXT(ctx
);
1324 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1325 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1326 GLenum ctype
= 0; /* color type */
1327 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1328 const GLint toffset
= 0; /* always zero */
1329 GLint defstride
; /* default stride */
1332 FLUSH_VERTICES(ctx
, 0);
1334 f
= sizeof(GLfloat
);
1335 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1338 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1344 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1345 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1350 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1351 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1356 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1357 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1358 ctype
= GL_UNSIGNED_BYTE
;
1361 defstride
= c
+ 2*f
;
1364 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1365 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1366 ctype
= GL_UNSIGNED_BYTE
;
1369 defstride
= c
+ 3*f
;
1372 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1373 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1380 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1381 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1386 case GL_C4F_N3F_V3F
:
1387 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1388 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1396 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1397 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1402 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1403 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1407 case GL_T2F_C4UB_V3F
:
1408 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1409 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1410 ctype
= GL_UNSIGNED_BYTE
;
1415 case GL_T2F_C3F_V3F
:
1416 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1417 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1423 case GL_T2F_N3F_V3F
:
1424 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1425 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1430 case GL_T2F_C4F_N3F_V3F
:
1431 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1432 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1439 case GL_T4F_C4F_N3F_V4F
:
1440 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1441 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1449 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1457 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1458 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1459 /* XXX also disable secondary color and generic arrays? */
1463 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1464 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1465 (GLubyte
*) pointer
+ toffset
);
1468 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1473 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1474 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1475 (GLubyte
*) pointer
+ coffset
);
1478 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1484 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1485 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1488 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1492 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1493 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1494 (GLubyte
*) pointer
+ voffset
);
1499 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1501 GET_CURRENT_CONTEXT(ctx
);
1503 FLUSH_VERTICES(ctx
, 0);
1505 if (MESA_VERBOSE
& VERBOSE_API
)
1506 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1509 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1513 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1516 if (ctx
->Array
.LockCount
!= 0) {
1517 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1521 ctx
->Array
.LockFirst
= first
;
1522 ctx
->Array
.LockCount
= count
;
1524 ctx
->NewState
|= _NEW_ARRAY
;
1529 _mesa_UnlockArraysEXT( void )
1531 GET_CURRENT_CONTEXT(ctx
);
1533 FLUSH_VERTICES(ctx
, 0);
1535 if (MESA_VERBOSE
& VERBOSE_API
)
1536 _mesa_debug(ctx
, "glUnlockArrays\n");
1538 if (ctx
->Array
.LockCount
== 0) {
1539 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1543 ctx
->Array
.LockFirst
= 0;
1544 ctx
->Array
.LockCount
= 0;
1545 ctx
->NewState
|= _NEW_ARRAY
;
1549 /* GL_EXT_multi_draw_arrays */
1551 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1552 const GLsizei
*count
, GLsizei primcount
)
1554 GET_CURRENT_CONTEXT(ctx
);
1557 FLUSH_VERTICES(ctx
, 0);
1559 for (i
= 0; i
< primcount
; i
++) {
1561 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1567 /* GL_IBM_multimode_draw_arrays */
1569 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1570 const GLsizei
* count
,
1571 GLsizei primcount
, GLint modestride
)
1573 GET_CURRENT_CONTEXT(ctx
);
1576 FLUSH_VERTICES(ctx
, 0);
1578 for ( i
= 0 ; i
< primcount
; i
++ ) {
1579 if ( count
[i
] > 0 ) {
1580 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1581 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1587 /* GL_IBM_multimode_draw_arrays */
1589 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1590 GLenum type
, const GLvoid
* const * indices
,
1591 GLsizei primcount
, GLint modestride
)
1593 GET_CURRENT_CONTEXT(ctx
);
1596 FLUSH_VERTICES(ctx
, 0);
1598 /* XXX not sure about ARB_vertex_buffer_object handling here */
1600 for ( i
= 0 ; i
< primcount
; i
++ ) {
1601 if ( count
[i
] > 0 ) {
1602 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1603 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1611 * GL_NV_primitive_restart and GL 3.1
1614 _mesa_PrimitiveRestartIndex(GLuint index
)
1616 GET_CURRENT_CONTEXT(ctx
);
1618 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1619 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1623 if (ctx
->Array
.RestartIndex
!= index
) {
1624 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1625 ctx
->Array
.RestartIndex
= index
;
1631 * See GL_ARB_instanced_arrays.
1632 * Note that the instance divisor only applies to generic arrays, not
1633 * the legacy vertex arrays.
1636 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1638 GET_CURRENT_CONTEXT(ctx
);
1640 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1641 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1643 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1644 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1648 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1649 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1654 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
1656 /* The ARB_vertex_attrib_binding spec says:
1660 * void VertexAttribDivisor(uint index, uint divisor);
1662 * is equivalent to (assuming no errors are generated):
1664 * VertexAttribBinding(index, index);
1665 * VertexBindingDivisor(index, divisor);"
1667 vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
1668 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
1673 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1675 /* From the OpenGL 4.3 core specification, page 302:
1676 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1677 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1680 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1682 case GL_UNSIGNED_BYTE
:
1684 case GL_UNSIGNED_SHORT
:
1686 case GL_UNSIGNED_INT
:
1689 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1693 return ctx
->Array
.RestartIndex
;
1698 * GL_ARB_vertex_attrib_binding
1701 vertex_array_vertex_buffer(struct gl_context
*ctx
,
1702 struct gl_vertex_array_object
*vao
,
1703 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1704 GLsizei stride
, const char *func
)
1706 struct gl_buffer_object
*vbo
;
1708 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1710 /* The ARB_vertex_attrib_binding spec says:
1712 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1713 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1715 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1716 _mesa_error(ctx
, GL_INVALID_VALUE
,
1717 "%s(bindingindex=%u > "
1718 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1719 func
, bindingIndex
);
1723 /* The ARB_vertex_attrib_binding spec says:
1725 * "The error INVALID_VALUE is generated if <stride> or <offset>
1729 _mesa_error(ctx
, GL_INVALID_VALUE
,
1730 "%s(offset=%" PRId64
" < 0)",
1731 func
, (int64_t) offset
);
1736 _mesa_error(ctx
, GL_INVALID_VALUE
,
1737 "%s(stride=%d < 0)", func
, stride
);
1741 if (((ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
1742 stride
> ctx
->Const
.MaxVertexAttribStride
) {
1743 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
1744 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
1749 vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1750 vbo
= vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1751 } else if (buffer
!= 0) {
1752 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1754 if (!vbo
&& _mesa_is_gles31(ctx
)) {
1755 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", func
);
1758 /* From the GL_ARB_vertex_attrib_array spec:
1760 * "[Core profile only:]
1761 * An INVALID_OPERATION error is generated if buffer is not zero or a
1762 * name returned from a previous call to GenBuffers, or if such a name
1763 * has since been deleted with DeleteBuffers.
1765 * Otherwise, we fall back to the same compat profile behavior as other
1766 * object references (automatically gen it).
1768 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
1771 /* The ARB_vertex_attrib_binding spec says:
1773 * "If <buffer> is zero, any buffer object attached to this
1774 * bindpoint is detached."
1776 vbo
= ctx
->Shared
->NullBufferObj
;
1779 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
1780 vbo
, offset
, stride
);
1785 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1788 GET_CURRENT_CONTEXT(ctx
);
1790 /* The ARB_vertex_attrib_binding spec says:
1792 * "An INVALID_OPERATION error is generated if no vertex array object
1795 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
1796 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1797 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1798 "glBindVertexBuffer(No array object bound)");
1802 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
1803 buffer
, offset
, stride
, "glBindVertexBuffer");
1808 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
1809 GLintptr offset
, GLsizei stride
)
1811 GET_CURRENT_CONTEXT(ctx
);
1812 struct gl_vertex_array_object
*vao
;
1814 /* The ARB_direct_state_access specification says:
1816 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1817 * if <vaobj> is not [compatibility profile: zero or] the name of an
1818 * existing vertex array object."
1820 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
1824 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
,
1825 buffer
, offset
, stride
,
1826 "glVertexArrayVertexBuffer");
1831 vertex_array_vertex_buffers(struct gl_context
*ctx
,
1832 struct gl_vertex_array_object
*vao
,
1833 GLuint first
, GLsizei count
, const GLuint
*buffers
,
1834 const GLintptr
*offsets
, const GLsizei
*strides
,
1839 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1841 /* The ARB_multi_bind spec says:
1843 * "An INVALID_OPERATION error is generated if <first> + <count>
1844 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1846 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1847 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1848 "%s(first=%u + count=%d > the value of "
1849 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1850 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1856 * The ARB_multi_bind spec says:
1858 * "If <buffers> is NULL, each affected vertex buffer binding point
1859 * from <first> through <first>+<count>-1 will be reset to have no
1860 * bound buffer object. In this case, the offsets and strides
1861 * associated with the binding points are set to default values,
1862 * ignoring <offsets> and <strides>."
1864 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1866 for (i
= 0; i
< count
; i
++)
1867 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1873 /* Note that the error semantics for multi-bind commands differ from
1874 * those of other GL commands.
1876 * The Issues section in the ARB_multi_bind spec says:
1878 * "(11) Typically, OpenGL specifies that if an error is generated by
1879 * a command, that command has no effect. This is somewhat
1880 * unfortunate for multi-bind commands, because it would require
1881 * a first pass to scan the entire list of bound objects for
1882 * errors and then a second pass to actually perform the
1883 * bindings. Should we have different error semantics?
1885 * RESOLVED: Yes. In this specification, when the parameters for
1886 * one of the <count> binding points are invalid, that binding
1887 * point is not updated and an error will be generated. However,
1888 * other binding points in the same command will be updated if
1889 * their parameters are valid and no other error occurs."
1892 _mesa_begin_bufferobj_lookups(ctx
);
1894 for (i
= 0; i
< count
; i
++) {
1895 struct gl_buffer_object
*vbo
;
1897 /* The ARB_multi_bind spec says:
1899 * "An INVALID_VALUE error is generated if any value in
1900 * <offsets> or <strides> is negative (per binding)."
1902 if (offsets
[i
] < 0) {
1903 _mesa_error(ctx
, GL_INVALID_VALUE
,
1904 "%s(offsets[%u]=%" PRId64
" < 0)",
1905 func
, i
, (int64_t) offsets
[i
]);
1909 if (strides
[i
] < 0) {
1910 _mesa_error(ctx
, GL_INVALID_VALUE
,
1911 "%s(strides[%u]=%d < 0)",
1912 func
, i
, strides
[i
]);
1916 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1917 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
1918 _mesa_error(ctx
, GL_INVALID_VALUE
,
1919 "%s(strides[%u]=%d > "
1920 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
1925 struct gl_vertex_buffer_binding
*binding
=
1926 &vao
->BufferBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1928 if (buffers
[i
] == binding
->BufferObj
->Name
)
1929 vbo
= binding
->BufferObj
;
1931 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
1936 vbo
= ctx
->Shared
->NullBufferObj
;
1939 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1940 vbo
, offsets
[i
], strides
[i
]);
1943 _mesa_end_bufferobj_lookups(ctx
);
1948 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1949 const GLintptr
*offsets
, const GLsizei
*strides
)
1951 GET_CURRENT_CONTEXT(ctx
);
1953 /* The ARB_vertex_attrib_binding spec says:
1955 * "An INVALID_OPERATION error is generated if no
1956 * vertex array object is bound."
1958 if (ctx
->API
== API_OPENGL_CORE
&&
1959 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1960 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1961 "glBindVertexBuffers(No array object bound)");
1965 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
1966 buffers
, offsets
, strides
,
1967 "glBindVertexBuffers");
1972 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
1973 const GLuint
*buffers
,
1974 const GLintptr
*offsets
, const GLsizei
*strides
)
1976 GET_CURRENT_CONTEXT(ctx
);
1977 struct gl_vertex_array_object
*vao
;
1979 /* The ARB_direct_state_access specification says:
1981 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1982 * if <vaobj> is not [compatibility profile: zero or] the name of an
1983 * existing vertex array object."
1985 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
1989 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
1990 buffers
, offsets
, strides
,
1991 "glVertexArrayVertexBuffers");
1996 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
1997 GLboolean normalized
, GLboolean integer
,
1998 GLboolean doubles
, GLbitfield legalTypes
,
1999 GLsizei maxSize
, GLuint relativeOffset
,
2002 GET_CURRENT_CONTEXT(ctx
);
2003 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2005 /* The ARB_vertex_attrib_binding spec says:
2007 * "An INVALID_OPERATION error is generated under any of the following
2009 * - if no vertex array object is currently bound (see section 2.10);
2012 * This error condition only applies to VertexAttribFormat and
2013 * VertexAttribIFormat in the extension spec, but we assume that this
2014 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2015 * to all three functions.
2017 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2018 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2019 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2020 "%s(No array object bound)", func
);
2024 /* The ARB_vertex_attrib_binding spec says:
2026 * "The error INVALID_VALUE is generated if index is greater than or equal
2027 * to the value of MAX_VERTEX_ATTRIBS."
2029 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2030 _mesa_error(ctx
, GL_INVALID_VALUE
,
2031 "%s(attribindex=%u > "
2032 "GL_MAX_VERTEX_ATTRIBS)",
2037 FLUSH_VERTICES(ctx
, 0);
2039 update_array_format(ctx
, func
, ctx
->Array
.VAO
,
2040 VERT_ATTRIB_GENERIC(attribIndex
),
2041 legalTypes
, 1, maxSize
, size
, type
,
2042 normalized
, integer
, doubles
, relativeOffset
);
2047 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2048 GLboolean normalized
, GLuint relativeOffset
)
2050 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
2051 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2052 BGRA_OR_4
, relativeOffset
,
2053 "glVertexAttribFormat");
2058 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2059 GLuint relativeOffset
)
2061 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
2062 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
2063 relativeOffset
, "glVertexAttribIFormat");
2068 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2069 GLuint relativeOffset
)
2071 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
2072 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
2073 relativeOffset
, "glVertexAttribLFormat");
2078 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2079 GLenum type
, GLboolean normalized
,
2080 GLboolean integer
, GLboolean doubles
,
2081 GLbitfield legalTypes
, GLsizei maxSize
,
2082 GLuint relativeOffset
, const char *func
)
2084 GET_CURRENT_CONTEXT(ctx
);
2085 struct gl_vertex_array_object
*vao
;
2087 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2089 /* The ARB_direct_state_access spec says:
2091 * "An INVALID_OPERATION error is generated by VertexArrayAttrib*Format
2092 * if <vaobj> is not [compatibility profile: zero or] the name of an
2093 * existing vertex array object."
2095 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
2099 /* The ARB_vertex_attrib_binding spec says:
2101 * "The error INVALID_VALUE is generated if index is greater than or equal
2102 * to the value of MAX_VERTEX_ATTRIBS."
2104 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2105 _mesa_error(ctx
, GL_INVALID_VALUE
,
2106 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2111 FLUSH_VERTICES(ctx
, 0);
2113 update_array_format(ctx
, func
, vao
,
2114 VERT_ATTRIB_GENERIC(attribIndex
),
2115 legalTypes
, 1, maxSize
, size
, type
, normalized
,
2116 integer
, doubles
, relativeOffset
);
2121 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2122 GLenum type
, GLboolean normalized
,
2123 GLuint relativeOffset
)
2125 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
2126 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2127 BGRA_OR_4
, relativeOffset
,
2128 "glVertexArrayAttribFormat");
2133 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
2134 GLint size
, GLenum type
,
2135 GLuint relativeOffset
)
2137 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2138 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
2140 "glVertexArrayAttribIFormat");
2145 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
2146 GLint size
, GLenum type
,
2147 GLuint relativeOffset
)
2149 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2150 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
2152 "glVertexArrayAttribLFormat");
2157 vertex_array_attrib_binding(struct gl_context
*ctx
,
2158 struct gl_vertex_array_object
*vao
,
2159 GLuint attribIndex
, GLuint bindingIndex
,
2162 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2164 /* The ARB_vertex_attrib_binding spec says:
2166 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2167 * <bindingindex> must be less than the value of
2168 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2171 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2172 _mesa_error(ctx
, GL_INVALID_VALUE
,
2173 "%s(attribindex=%u >= "
2174 "GL_MAX_VERTEX_ATTRIBS)",
2179 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2180 _mesa_error(ctx
, GL_INVALID_VALUE
,
2181 "%s(bindingindex=%u >= "
2182 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2183 func
, bindingIndex
);
2187 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
2189 vertex_attrib_binding(ctx
, vao
,
2190 VERT_ATTRIB_GENERIC(attribIndex
),
2191 VERT_ATTRIB_GENERIC(bindingIndex
));
2196 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2198 GET_CURRENT_CONTEXT(ctx
);
2200 /* The ARB_vertex_attrib_binding spec says:
2202 * "An INVALID_OPERATION error is generated if no vertex array object
2205 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2206 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2207 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2208 "glVertexAttribBinding(No array object bound)");
2212 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2213 attribIndex
, bindingIndex
,
2214 "glVertexAttribBinding");
2219 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2221 GET_CURRENT_CONTEXT(ctx
);
2222 struct gl_vertex_array_object
*vao
;
2224 /* The ARB_direct_state_access specification says:
2226 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2227 * if <vaobj> is not [compatibility profile: zero or] the name of an
2228 * existing vertex array object."
2230 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2234 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2235 "glVertexArrayAttribBinding");
2240 vertex_array_binding_divisor(struct gl_context
*ctx
,
2241 struct gl_vertex_array_object
*vao
,
2242 GLuint bindingIndex
, GLuint divisor
,
2245 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2247 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2248 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
2252 /* The ARB_vertex_attrib_binding spec says:
2254 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2255 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2257 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2258 _mesa_error(ctx
, GL_INVALID_VALUE
,
2259 "%s(bindingindex=%u > "
2260 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2261 func
, bindingIndex
);
2265 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2270 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2272 GET_CURRENT_CONTEXT(ctx
);
2274 /* The ARB_vertex_attrib_binding spec says:
2276 * "An INVALID_OPERATION error is generated if no vertex array object
2279 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2280 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2281 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2282 "glVertexBindingDivisor(No array object bound)");
2286 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
2287 bindingIndex
, divisor
,
2288 "glVertexBindingDivisor");
2293 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
2296 struct gl_vertex_array_object
*vao
;
2297 GET_CURRENT_CONTEXT(ctx
);
2299 /* The ARB_direct_state_access specification says:
2301 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2302 * if <vaobj> is not [compatibility profile: zero or] the name of an
2303 * existing vertex array object."
2305 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayBindingDivisor");
2309 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
2310 "glVertexArrayBindingDivisor");
2315 * Copy one client vertex array to another.
2318 _mesa_copy_client_array(struct gl_context
*ctx
,
2319 struct gl_vertex_array
*dst
,
2320 struct gl_vertex_array
*src
)
2322 dst
->Size
= src
->Size
;
2323 dst
->Type
= src
->Type
;
2324 dst
->Format
= src
->Format
;
2325 dst
->StrideB
= src
->StrideB
;
2326 dst
->Ptr
= src
->Ptr
;
2327 dst
->Normalized
= src
->Normalized
;
2328 dst
->Integer
= src
->Integer
;
2329 dst
->Doubles
= src
->Doubles
;
2330 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2331 dst
->_ElementSize
= src
->_ElementSize
;
2332 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2336 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2337 struct gl_array_attributes
*dst
,
2338 const struct gl_array_attributes
*src
)
2340 dst
->Size
= src
->Size
;
2341 dst
->Type
= src
->Type
;
2342 dst
->Format
= src
->Format
;
2343 dst
->BufferBindingIndex
= src
->BufferBindingIndex
;
2344 dst
->RelativeOffset
= src
->RelativeOffset
;
2345 dst
->Format
= src
->Format
;
2346 dst
->Integer
= src
->Integer
;
2347 dst
->Doubles
= src
->Doubles
;
2348 dst
->Normalized
= src
->Normalized
;
2349 dst
->Ptr
= src
->Ptr
;
2350 dst
->Enabled
= src
->Enabled
;
2351 dst
->_ElementSize
= src
->_ElementSize
;
2355 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2356 struct gl_vertex_buffer_binding
*dst
,
2357 const struct gl_vertex_buffer_binding
*src
)
2359 dst
->Offset
= src
->Offset
;
2360 dst
->Stride
= src
->Stride
;
2361 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2362 dst
->_BoundArrays
= src
->_BoundArrays
;
2364 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2368 * Print current vertex object/array info. For debug.
2371 _mesa_print_arrays(struct gl_context
*ctx
)
2373 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2375 fprintf(stderr
, "Array Object %u\n", vao
->Name
);
2378 for (i
= 0; i
< VERT_ATTRIB_MAX
; ++i
) {
2379 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
2380 if (!array
->Enabled
)
2383 const struct gl_vertex_buffer_binding
*binding
=
2384 &vao
->BufferBinding
[array
->BufferBindingIndex
];
2385 const struct gl_buffer_object
*bo
= binding
->BufferObj
;
2387 fprintf(stderr
, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
2388 "Stride=%d, Buffer=%u(Size %lu)\n",
2389 gl_vert_attrib_name((gl_vert_attrib
)i
),
2390 array
->Ptr
, _mesa_enum_to_string(array
->Type
), array
->Size
,
2391 array
->_ElementSize
, binding
->Stride
, bo
->Name
,
2392 (unsigned long) bo
->Size
);
2398 * Initialize vertex array state for given context.
2401 _mesa_init_varray(struct gl_context
*ctx
)
2403 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
2404 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2405 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2407 ctx
->Array
.Objects
= _mesa_NewHashTable();
2412 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2415 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2417 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2418 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2419 _mesa_delete_vao(ctx
, vao
);
2424 * Free vertex array state for given context.
2427 _mesa_free_varray_data(struct gl_context
*ctx
)
2429 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2430 _mesa_DeleteHashTable(ctx
->Array
.Objects
);