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 BufferBindingIndex field for the vertex attribute given by
132 vertex_attrib_binding(struct gl_context
*ctx
,
133 struct gl_vertex_array_object
*vao
,
137 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attribIndex
];
139 if (!_mesa_is_bufferobj(vao
->BufferBinding
[bindingIndex
].BufferObj
))
140 vao
->VertexAttribBufferMask
&= ~VERT_BIT(attribIndex
);
142 vao
->VertexAttribBufferMask
|= VERT_BIT(attribIndex
);
144 if (array
->BufferBindingIndex
!= bindingIndex
) {
145 const GLbitfield64 array_bit
= VERT_BIT(attribIndex
);
147 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
149 vao
->BufferBinding
[array
->BufferBindingIndex
]._BoundArrays
&= ~array_bit
;
150 vao
->BufferBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
152 array
->BufferBindingIndex
= bindingIndex
;
154 vao
->NewArrays
|= array_bit
;
160 * Binds a buffer object to the vertex buffer binding point given by index,
161 * and sets the Offset and Stride fields.
164 _mesa_bind_vertex_buffer(struct gl_context
*ctx
,
165 struct gl_vertex_array_object
*vao
,
167 struct gl_buffer_object
*vbo
,
168 GLintptr offset
, GLsizei stride
)
170 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
172 if (binding
->BufferObj
!= vbo
||
173 binding
->Offset
!= offset
||
174 binding
->Stride
!= stride
) {
176 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
178 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
180 binding
->Offset
= offset
;
181 binding
->Stride
= stride
;
183 if (!_mesa_is_bufferobj(vbo
))
184 vao
->VertexAttribBufferMask
&= ~binding
->_BoundArrays
;
186 vao
->VertexAttribBufferMask
|= binding
->_BoundArrays
;
188 vao
->NewArrays
|= binding
->_BoundArrays
;
194 * Sets the InstanceDivisor field in the vertex buffer binding point
195 * given by bindingIndex.
198 vertex_binding_divisor(struct gl_context
*ctx
,
199 struct gl_vertex_array_object
*vao
,
203 struct gl_vertex_buffer_binding
*binding
=
204 &vao
->BufferBinding
[bindingIndex
];
206 if (binding
->InstanceDivisor
!= divisor
) {
207 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
208 binding
->InstanceDivisor
= divisor
;
209 vao
->NewArrays
|= binding
->_BoundArrays
;
215 * Examine the API profile and extensions to determine which types are legal
216 * for vertex arrays. This is called once from update_array_format().
219 get_legal_types_mask(const struct gl_context
*ctx
)
221 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
223 if (_mesa_is_gles(ctx
)) {
224 legalTypesMask
&= ~(FIXED_GL_BIT
|
226 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
228 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
229 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
230 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
231 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
232 * quite as trivial as we'd like because it uses a different enum value
233 * for GL_HALF_FLOAT_OES.
235 if (ctx
->Version
< 30) {
236 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
238 UNSIGNED_INT_2_10_10_10_REV_BIT
|
239 INT_2_10_10_10_REV_BIT
|
244 legalTypesMask
&= ~FIXED_ES_BIT
;
246 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
247 legalTypesMask
&= ~FIXED_GL_BIT
;
249 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
250 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
251 INT_2_10_10_10_REV_BIT
);
253 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
254 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
257 return legalTypesMask
;
262 * \param attrib The index of the attribute array
263 * \param size Components per element (1, 2, 3 or 4)
264 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
265 * \param format Either GL_RGBA or GL_BGRA.
266 * \param normalized Whether integer types are converted to floats in [-1, 1]
267 * \param integer Integer-valued values (will not be normalized to [-1, 1])
268 * \param doubles Double values not reduced to floats
269 * \param relativeOffset Offset of the first element relative to the binding
271 * \param flush_verties Should \c FLUSH_VERTICES be invoked before updating
275 _mesa_update_array_format(struct gl_context
*ctx
,
276 struct gl_vertex_array_object
*vao
,
277 GLuint attrib
, GLint size
, GLenum type
,
278 GLenum format
, GLboolean normalized
,
279 GLboolean integer
, GLboolean doubles
,
280 GLuint relativeOffset
, bool flush_vertices
)
282 struct gl_array_attributes
*const array
= &vao
->VertexAttrib
[attrib
];
287 if (flush_vertices
) {
288 FLUSH_VERTICES(ctx
, 0);
291 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
292 assert(elementSize
!= -1);
296 array
->Format
= format
;
297 array
->Normalized
= normalized
;
298 array
->Integer
= integer
;
299 array
->Doubles
= doubles
;
300 array
->RelativeOffset
= relativeOffset
;
301 array
->_ElementSize
= elementSize
;
303 vao
->NewArrays
|= VERT_BIT(attrib
);
304 ctx
->NewState
|= _NEW_ARRAY
;
308 * Does error checking and updates the format in an attrib array.
310 * Called by update_array() and VertexAttrib*Format().
312 * \param func Name of calling function used for error reporting
313 * \param attrib The index of the attribute array
314 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
315 * \param sizeMin Min allowable size value
316 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
317 * \param size Components per element (1, 2, 3 or 4)
318 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
319 * \param normalized Whether integer types are converted to floats in [-1, 1]
320 * \param integer Integer-valued values (will not be normalized to [-1, 1])
321 * \param doubles Double values not reduced to floats
322 * \param relativeOffset Offset of the first element relative to the binding offset.
325 update_array_format(struct gl_context
*ctx
,
327 struct gl_vertex_array_object
*vao
,
328 GLuint attrib
, GLbitfield legalTypesMask
,
329 GLint sizeMin
, GLint sizeMax
,
330 GLint size
, GLenum type
,
331 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
332 GLuint relativeOffset
)
335 GLenum format
= GL_RGBA
;
337 /* at most, one of these bools can be true */
338 assert((int) normalized
+ (int) integer
+ (int) doubles
<= 1);
340 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
341 /* Compute the LegalTypesMask only once, unless the context API has
342 * changed, in which case we want to compute it again. We can't do this
343 * in _mesa_init_varrays() below because extensions are not yet enabled
346 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
347 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
350 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
352 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
353 /* BGRA ordering is not supported in ES contexts.
358 typeBit
= type_to_bit(ctx
, type
);
359 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
360 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
361 func
, _mesa_enum_to_string(type
));
365 /* Do size parameter checking.
366 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
367 * must be handled specially.
369 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
370 sizeMax
== BGRA_OR_4
&&
372 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
374 * "An INVALID_OPERATION error is generated under any of the following
377 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
378 * or UNSIGNED_INT_2_10_10_10_REV;
380 * • size is BGRA and normalized is FALSE;"
382 bool bgra_error
= false;
384 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
385 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
386 type
!= GL_INT_2_10_10_10_REV
&&
387 type
!= GL_UNSIGNED_BYTE
)
389 } else if (type
!= GL_UNSIGNED_BYTE
)
393 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
394 func
, _mesa_enum_to_string(type
));
399 _mesa_error(ctx
, GL_INVALID_OPERATION
,
400 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
407 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
408 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
412 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
413 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
414 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
415 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
419 /* The ARB_vertex_attrib_binding_spec says:
421 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
422 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
424 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
425 _mesa_error(ctx
, GL_INVALID_VALUE
,
426 "%s(relativeOffset=%d > "
427 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
428 func
, relativeOffset
);
432 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
433 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
434 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
438 _mesa_update_array_format(ctx
, vao
, attrib
, size
, type
, format
,
439 normalized
, integer
, doubles
, relativeOffset
,
447 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
450 * \param func name of calling function used for error reporting
451 * \param attrib the attribute array index to update
452 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
453 * \param sizeMin min allowable size value
454 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
455 * \param size components per element (1, 2, 3 or 4)
456 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
457 * \param stride stride between elements, in elements
458 * \param normalized are integer types converted to floats in [-1, 1]?
459 * \param integer integer-valued values (will not be normalized to [-1,1])
460 * \param doubles Double values not reduced to floats
461 * \param ptr the address (or offset inside VBO) of the array data
464 update_array(struct gl_context
*ctx
,
466 GLuint attrib
, GLbitfield legalTypesMask
,
467 GLint sizeMin
, GLint sizeMax
,
468 GLint size
, GLenum type
, GLsizei stride
,
469 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
472 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
473 struct gl_array_attributes
*array
;
474 GLsizei effectiveStride
;
476 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
478 * "Client vertex arrays - all vertex array attribute pointers must
479 * refer to buffer objects (section 2.9.2). The default vertex array
480 * object (the name zero) is also deprecated. Calling
481 * VertexAttribPointer when no buffer object or no vertex array object
482 * is bound will generate an INVALID_OPERATION error..."
484 * The check for VBOs is handled below.
486 if (ctx
->API
== API_OPENGL_CORE
&& (vao
== ctx
->Array
.DefaultVAO
)) {
487 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
493 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
497 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
498 stride
> ctx
->Const
.MaxVertexAttribStride
) {
499 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
500 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
504 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
506 * "An INVALID_OPERATION error is generated under any of the following
511 * * any of the *Pointer commands specifying the location and
512 * organization of vertex array data are called while zero is bound
513 * to the ARRAY_BUFFER buffer object binding point (see section
514 * 2.9.6), and the pointer argument is not NULL."
516 if (ptr
!= NULL
&& vao
->ARBsemantics
&&
517 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
518 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
522 if (!update_array_format(ctx
, func
, vao
, attrib
,
523 legalTypesMask
, sizeMin
, sizeMax
,
524 size
, type
, normalized
, integer
, doubles
, 0)) {
528 /* Reset the vertex attrib binding */
529 vertex_attrib_binding(ctx
, vao
, attrib
, attrib
);
531 /* The Stride and Ptr fields are not set by update_array_format() */
532 array
= &vao
->VertexAttrib
[attrib
];
533 array
->Stride
= stride
;
536 /* Update the vertex buffer binding */
537 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
538 _mesa_bind_vertex_buffer(ctx
, vao
, attrib
,
539 ctx
->Array
.ArrayBufferObj
, (GLintptr
) ptr
,
545 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
547 GET_CURRENT_CONTEXT(ctx
);
548 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
549 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
550 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
551 DOUBLE_BIT
| HALF_BIT
|
552 UNSIGNED_INT_2_10_10_10_REV_BIT
|
553 INT_2_10_10_10_REV_BIT
);
555 FLUSH_VERTICES(ctx
, 0);
557 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
559 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
564 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
566 GET_CURRENT_CONTEXT(ctx
);
567 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
568 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
569 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
570 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
571 UNSIGNED_INT_2_10_10_10_REV_BIT
|
572 INT_2_10_10_10_REV_BIT
);
574 FLUSH_VERTICES(ctx
, 0);
576 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
578 3, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
583 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
585 GET_CURRENT_CONTEXT(ctx
);
586 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
587 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
588 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
589 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
590 INT_BIT
| UNSIGNED_INT_BIT
|
591 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
592 UNSIGNED_INT_2_10_10_10_REV_BIT
|
593 INT_2_10_10_10_REV_BIT
);
594 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
596 FLUSH_VERTICES(ctx
, 0);
598 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
599 legalTypes
, sizeMin
, BGRA_OR_4
,
600 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
605 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
607 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
608 GET_CURRENT_CONTEXT(ctx
);
610 FLUSH_VERTICES(ctx
, 0);
612 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
614 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
619 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
621 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
622 FLOAT_BIT
| DOUBLE_BIT
);
623 GET_CURRENT_CONTEXT(ctx
);
625 FLUSH_VERTICES(ctx
, 0);
627 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
629 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
634 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
635 GLsizei stride
, const GLvoid
*ptr
)
637 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
638 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
639 INT_BIT
| UNSIGNED_INT_BIT
|
640 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
641 UNSIGNED_INT_2_10_10_10_REV_BIT
|
642 INT_2_10_10_10_REV_BIT
);
643 GET_CURRENT_CONTEXT(ctx
);
645 FLUSH_VERTICES(ctx
, 0);
647 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
648 legalTypes
, 3, BGRA_OR_4
,
649 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
654 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
657 GET_CURRENT_CONTEXT(ctx
);
658 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
659 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
660 : (SHORT_BIT
| INT_BIT
|
661 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
662 UNSIGNED_INT_2_10_10_10_REV_BIT
|
663 INT_2_10_10_10_REV_BIT
);
664 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
665 const GLuint unit
= ctx
->Array
.ActiveTexture
;
667 FLUSH_VERTICES(ctx
, 0);
669 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
670 legalTypes
, sizeMin
, 4,
671 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
677 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
679 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
680 /* this is the same type that glEdgeFlag uses */
681 const GLboolean integer
= GL_FALSE
;
682 GET_CURRENT_CONTEXT(ctx
);
684 FLUSH_VERTICES(ctx
, 0);
686 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
688 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
693 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
695 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
696 GET_CURRENT_CONTEXT(ctx
);
698 FLUSH_VERTICES(ctx
, 0);
700 if (ctx
->API
!= API_OPENGLES
) {
701 _mesa_error(ctx
, GL_INVALID_OPERATION
,
702 "glPointSizePointer(ES 1.x only)");
706 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
708 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
713 * Set a generic vertex attribute array.
714 * Note that these arrays DO NOT alias the conventional GL vertex arrays
715 * (position, normal, color, fog, texcoord, etc).
718 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
719 GLboolean normalized
,
720 GLsizei stride
, const GLvoid
*ptr
)
722 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
723 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
724 INT_BIT
| UNSIGNED_INT_BIT
|
725 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
726 FIXED_ES_BIT
| FIXED_GL_BIT
|
727 UNSIGNED_INT_2_10_10_10_REV_BIT
|
728 INT_2_10_10_10_REV_BIT
|
729 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
730 GET_CURRENT_CONTEXT(ctx
);
732 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
733 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
737 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
738 legalTypes
, 1, BGRA_OR_4
,
739 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
744 * GL_EXT_gpu_shader4 / GL 3.0.
745 * Set an integer-valued vertex attribute array.
746 * Note that these arrays DO NOT alias the conventional GL vertex arrays
747 * (position, normal, color, fog, texcoord, etc).
750 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
751 GLsizei stride
, const GLvoid
*ptr
)
753 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
754 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
755 INT_BIT
| UNSIGNED_INT_BIT
);
756 const GLboolean normalized
= GL_FALSE
;
757 const GLboolean integer
= GL_TRUE
;
758 GET_CURRENT_CONTEXT(ctx
);
760 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
761 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
765 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
767 size
, type
, stride
, normalized
, integer
, GL_FALSE
, ptr
);
771 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
772 GLsizei stride
, const GLvoid
*ptr
)
774 GET_CURRENT_CONTEXT(ctx
);
775 const GLbitfield legalTypes
= (DOUBLE_BIT
);
776 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
777 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
781 update_array(ctx
, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index
),
783 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
788 _mesa_enable_vertex_array_attrib(struct gl_context
*ctx
,
789 struct gl_vertex_array_object
*vao
,
792 assert(attrib
< ARRAY_SIZE(vao
->VertexAttrib
));
794 if (!vao
->VertexAttrib
[attrib
].Enabled
) {
795 /* was disabled, now being enabled */
796 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
797 vao
->VertexAttrib
[attrib
].Enabled
= GL_TRUE
;
798 vao
->_Enabled
|= VERT_BIT(attrib
);
799 vao
->NewArrays
|= VERT_BIT(attrib
);
804 enable_vertex_array_attrib(struct gl_context
*ctx
,
805 struct gl_vertex_array_object
*vao
,
809 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
810 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
814 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
819 _mesa_EnableVertexAttribArray(GLuint index
)
821 GET_CURRENT_CONTEXT(ctx
);
822 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
823 "glEnableVertexAttribArray");
828 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
830 GET_CURRENT_CONTEXT(ctx
);
831 struct gl_vertex_array_object
*vao
;
833 /* The ARB_direct_state_access specification says:
835 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
836 * and DisableVertexArrayAttrib if <vaobj> is not
837 * [compatibility profile: zero or] the name of an existing vertex
840 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
844 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
849 disable_vertex_array_attrib(struct gl_context
*ctx
,
850 struct gl_vertex_array_object
*vao
,
854 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
855 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
859 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
861 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
862 /* was enabled, now being disabled */
863 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
864 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
865 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
866 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
872 _mesa_DisableVertexAttribArray(GLuint index
)
874 GET_CURRENT_CONTEXT(ctx
);
875 disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
876 "glDisableVertexAttribArray");
881 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
883 GET_CURRENT_CONTEXT(ctx
);
884 struct gl_vertex_array_object
*vao
;
886 /* The ARB_direct_state_access specification says:
888 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
889 * and DisableVertexArrayAttrib if <vaobj> is not
890 * [compatibility profile: zero or] the name of an existing vertex
893 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
897 disable_vertex_array_attrib(ctx
, vao
, index
, "glDisableVertexArrayAttrib");
902 * Return info for a vertex attribute array (no alias with legacy
903 * vertex attributes (pos, normal, color, etc)). This function does
904 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
907 get_vertex_array_attrib(struct gl_context
*ctx
,
908 const struct gl_vertex_array_object
*vao
,
909 GLuint index
, GLenum pname
,
912 const struct gl_array_attributes
*array
;
914 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
915 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
919 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
921 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
924 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
925 return array
->Enabled
;
926 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
927 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
928 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
929 return array
->Stride
;
930 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
932 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
933 return array
->Normalized
;
934 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
935 return vao
->BufferBinding
[array
->BufferBindingIndex
].BufferObj
->Name
;
936 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
937 if ((_mesa_is_desktop_gl(ctx
)
938 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
939 || _mesa_is_gles3(ctx
)) {
940 return array
->Integer
;
943 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
944 if (_mesa_is_desktop_gl(ctx
)) {
945 return array
->Doubles
;
948 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
949 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
950 || _mesa_is_gles3(ctx
)) {
951 return vao
->BufferBinding
[array
->BufferBindingIndex
].InstanceDivisor
;
954 case GL_VERTEX_ATTRIB_BINDING
:
955 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
956 return array
->BufferBindingIndex
- VERT_ATTRIB_GENERIC0
;
959 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
960 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
961 return array
->RelativeOffset
;
969 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
974 static const GLfloat
*
975 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
978 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
979 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
983 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
984 _mesa_error(ctx
, GL_INVALID_VALUE
,
985 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
989 assert(VERT_ATTRIB_GENERIC(index
) <
990 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
992 FLUSH_CURRENT(ctx
, 0);
993 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
997 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
999 GET_CURRENT_CONTEXT(ctx
);
1001 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1002 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
1008 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1010 "glGetVertexAttribfv");
1016 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1018 GET_CURRENT_CONTEXT(ctx
);
1020 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1021 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
1023 params
[0] = (GLdouble
) v
[0];
1024 params
[1] = (GLdouble
) v
[1];
1025 params
[2] = (GLdouble
) v
[2];
1026 params
[3] = (GLdouble
) v
[3];
1030 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1032 "glGetVertexAttribdv");
1037 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1039 GET_CURRENT_CONTEXT(ctx
);
1041 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1043 (const GLdouble
*)get_current_attrib(ctx
, index
,
1044 "glGetVertexAttribLdv");
1053 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1055 "glGetVertexAttribLdv");
1060 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
1062 GET_CURRENT_CONTEXT(ctx
);
1064 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1065 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1067 /* XXX should floats in[0,1] be scaled to full int range? */
1068 params
[0] = (GLint
) v
[0];
1069 params
[1] = (GLint
) v
[1];
1070 params
[2] = (GLint
) v
[2];
1071 params
[3] = (GLint
) v
[3];
1075 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1077 "glGetVertexAttribiv");
1084 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1086 GET_CURRENT_CONTEXT(ctx
);
1088 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1089 const GLint
*v
= (const GLint
*)
1090 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1096 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1098 "glGetVertexAttribIiv");
1105 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1107 GET_CURRENT_CONTEXT(ctx
);
1109 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1110 const GLuint
*v
= (const GLuint
*)
1111 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1117 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1119 "glGetVertexAttribIuiv");
1125 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1127 GET_CURRENT_CONTEXT(ctx
);
1129 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1130 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1134 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1135 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1139 assert(VERT_ATTRIB_GENERIC(index
) <
1140 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1142 *pointer
= (GLvoid
*)
1143 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1147 /** ARB_direct_state_access */
1149 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
1150 GLenum pname
, GLint
*params
)
1152 GET_CURRENT_CONTEXT(ctx
);
1153 struct gl_vertex_array_object
*vao
;
1155 /* The ARB_direct_state_access specification says:
1157 * "An INVALID_OPERATION error is generated if <vaobj> is not
1158 * [compatibility profile: zero or] the name of an existing
1159 * vertex array object."
1161 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexediv");
1165 /* The ARB_direct_state_access specification says:
1167 * "For GetVertexArrayIndexediv, <pname> must be one of
1168 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1169 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1170 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1171 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1172 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1176 * "Add GetVertexArrayIndexediv in 'Get Command' for
1177 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1178 * VERTEX_ATTRIB_BINDING,
1179 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1180 * VERTEX_BINDING_OFFSET, and
1181 * VERTEX_BINDING_STRIDE states"
1183 * The only parameter name common to both lists is
1184 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1185 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1186 * pretty clear however that the intent is that it should be possible
1187 * to query all vertex attrib and binding states that can be set with
1191 case GL_VERTEX_BINDING_OFFSET
:
1192 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1194 case GL_VERTEX_BINDING_STRIDE
:
1195 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
1197 case GL_VERTEX_BINDING_DIVISOR
:
1198 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
1200 case GL_VERTEX_BINDING_BUFFER
:
1201 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
1204 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
1205 "glGetVertexArrayIndexediv");
1212 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
1213 GLenum pname
, GLint64
*params
)
1215 GET_CURRENT_CONTEXT(ctx
);
1216 struct gl_vertex_array_object
*vao
;
1218 /* The ARB_direct_state_access specification says:
1220 * "An INVALID_OPERATION error is generated if <vaobj> is not
1221 * [compatibility profile: zero or] the name of an existing
1222 * vertex array object."
1224 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexed64iv");
1228 /* The ARB_direct_state_access specification says:
1230 * "For GetVertexArrayIndexed64iv, <pname> must be
1231 * VERTEX_BINDING_OFFSET."
1235 * "An INVALID_ENUM error is generated if <pname> is not one of
1236 * the valid values listed above for the corresponding command."
1238 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
1239 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
1240 "pname != GL_VERTEX_BINDING_OFFSET)");
1244 /* The ARB_direct_state_access specification says:
1246 * "An INVALID_VALUE error is generated if <index> is greater than
1247 * or equal to the value of MAX_VERTEX_ATTRIBS."
1249 * Since the index refers to a buffer binding in this case, the intended
1250 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1251 * required to be the same, so in practice this doesn't matter.
1253 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
1254 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
1255 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1256 index
, ctx
->Const
.MaxVertexAttribBindings
);
1260 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1265 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1266 GLsizei count
, const GLvoid
*ptr
)
1269 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1274 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1278 _mesa_NormalPointer(type
, stride
, ptr
);
1283 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1287 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1292 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1296 _mesa_IndexPointer(type
, stride
, ptr
);
1301 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1302 GLsizei count
, const GLvoid
*ptr
)
1305 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1310 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1313 _mesa_EdgeFlagPointer(stride
, ptr
);
1318 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1320 GET_CURRENT_CONTEXT(ctx
);
1321 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1322 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1323 GLenum ctype
= 0; /* color type */
1324 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1325 const GLint toffset
= 0; /* always zero */
1326 GLint defstride
; /* default stride */
1329 FLUSH_VERTICES(ctx
, 0);
1331 f
= sizeof(GLfloat
);
1332 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1335 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1341 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1342 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1347 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1348 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1353 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1354 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1355 ctype
= GL_UNSIGNED_BYTE
;
1358 defstride
= c
+ 2*f
;
1361 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1362 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1363 ctype
= GL_UNSIGNED_BYTE
;
1366 defstride
= c
+ 3*f
;
1369 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1370 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1377 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1378 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1383 case GL_C4F_N3F_V3F
:
1384 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1385 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1393 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1394 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1399 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1400 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1404 case GL_T2F_C4UB_V3F
:
1405 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1406 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1407 ctype
= GL_UNSIGNED_BYTE
;
1412 case GL_T2F_C3F_V3F
:
1413 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1414 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1420 case GL_T2F_N3F_V3F
:
1421 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1422 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1427 case GL_T2F_C4F_N3F_V3F
:
1428 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1429 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1436 case GL_T4F_C4F_N3F_V4F
:
1437 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1438 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1446 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1454 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1455 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1456 /* XXX also disable secondary color and generic arrays? */
1460 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1461 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1462 (GLubyte
*) pointer
+ toffset
);
1465 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1470 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1471 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1472 (GLubyte
*) pointer
+ coffset
);
1475 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1481 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1482 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1485 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1489 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1490 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1491 (GLubyte
*) pointer
+ voffset
);
1496 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1498 GET_CURRENT_CONTEXT(ctx
);
1500 FLUSH_VERTICES(ctx
, 0);
1502 if (MESA_VERBOSE
& VERBOSE_API
)
1503 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1506 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1510 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1513 if (ctx
->Array
.LockCount
!= 0) {
1514 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1518 ctx
->Array
.LockFirst
= first
;
1519 ctx
->Array
.LockCount
= count
;
1521 ctx
->NewState
|= _NEW_ARRAY
;
1526 _mesa_UnlockArraysEXT( void )
1528 GET_CURRENT_CONTEXT(ctx
);
1530 FLUSH_VERTICES(ctx
, 0);
1532 if (MESA_VERBOSE
& VERBOSE_API
)
1533 _mesa_debug(ctx
, "glUnlockArrays\n");
1535 if (ctx
->Array
.LockCount
== 0) {
1536 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1540 ctx
->Array
.LockFirst
= 0;
1541 ctx
->Array
.LockCount
= 0;
1542 ctx
->NewState
|= _NEW_ARRAY
;
1546 /* GL_EXT_multi_draw_arrays */
1548 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1549 const GLsizei
*count
, GLsizei primcount
)
1551 GET_CURRENT_CONTEXT(ctx
);
1554 FLUSH_VERTICES(ctx
, 0);
1556 for (i
= 0; i
< primcount
; i
++) {
1558 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1564 /* GL_IBM_multimode_draw_arrays */
1566 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1567 const GLsizei
* count
,
1568 GLsizei primcount
, GLint modestride
)
1570 GET_CURRENT_CONTEXT(ctx
);
1573 FLUSH_VERTICES(ctx
, 0);
1575 for ( i
= 0 ; i
< primcount
; i
++ ) {
1576 if ( count
[i
] > 0 ) {
1577 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1578 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1584 /* GL_IBM_multimode_draw_arrays */
1586 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1587 GLenum type
, const GLvoid
* const * indices
,
1588 GLsizei primcount
, GLint modestride
)
1590 GET_CURRENT_CONTEXT(ctx
);
1593 FLUSH_VERTICES(ctx
, 0);
1595 /* XXX not sure about ARB_vertex_buffer_object handling here */
1597 for ( i
= 0 ; i
< primcount
; i
++ ) {
1598 if ( count
[i
] > 0 ) {
1599 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1600 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1608 * GL_NV_primitive_restart and GL 3.1
1611 _mesa_PrimitiveRestartIndex(GLuint index
)
1613 GET_CURRENT_CONTEXT(ctx
);
1615 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1616 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1620 if (ctx
->Array
.RestartIndex
!= index
) {
1621 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1622 ctx
->Array
.RestartIndex
= index
;
1628 * See GL_ARB_instanced_arrays.
1629 * Note that the instance divisor only applies to generic arrays, not
1630 * the legacy vertex arrays.
1633 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1635 GET_CURRENT_CONTEXT(ctx
);
1637 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1638 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1640 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1641 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1645 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1646 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1651 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
1653 /* The ARB_vertex_attrib_binding spec says:
1657 * void VertexAttribDivisor(uint index, uint divisor);
1659 * is equivalent to (assuming no errors are generated):
1661 * VertexAttribBinding(index, index);
1662 * VertexBindingDivisor(index, divisor);"
1664 vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
1665 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
1670 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1672 /* From the OpenGL 4.3 core specification, page 302:
1673 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1674 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1677 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1679 case GL_UNSIGNED_BYTE
:
1681 case GL_UNSIGNED_SHORT
:
1683 case GL_UNSIGNED_INT
:
1686 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1690 return ctx
->Array
.RestartIndex
;
1695 * GL_ARB_vertex_attrib_binding
1698 vertex_array_vertex_buffer(struct gl_context
*ctx
,
1699 struct gl_vertex_array_object
*vao
,
1700 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1701 GLsizei stride
, const char *func
)
1703 struct gl_buffer_object
*vbo
;
1705 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1707 /* The ARB_vertex_attrib_binding spec says:
1709 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1710 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1712 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1713 _mesa_error(ctx
, GL_INVALID_VALUE
,
1714 "%s(bindingindex=%u > "
1715 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1716 func
, bindingIndex
);
1720 /* The ARB_vertex_attrib_binding spec says:
1722 * "The error INVALID_VALUE is generated if <stride> or <offset>
1726 _mesa_error(ctx
, GL_INVALID_VALUE
,
1727 "%s(offset=%" PRId64
" < 0)",
1728 func
, (int64_t) offset
);
1733 _mesa_error(ctx
, GL_INVALID_VALUE
,
1734 "%s(stride=%d < 0)", func
, stride
);
1738 if (((ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
1739 stride
> ctx
->Const
.MaxVertexAttribStride
) {
1740 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
1741 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
1746 vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1747 vbo
= vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1748 } else if (buffer
!= 0) {
1749 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1751 if (!vbo
&& _mesa_is_gles31(ctx
)) {
1752 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", func
);
1755 /* From the GL_ARB_vertex_attrib_array spec:
1757 * "[Core profile only:]
1758 * An INVALID_OPERATION error is generated if buffer is not zero or a
1759 * name returned from a previous call to GenBuffers, or if such a name
1760 * has since been deleted with DeleteBuffers.
1762 * Otherwise, we fall back to the same compat profile behavior as other
1763 * object references (automatically gen it).
1765 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
1768 /* The ARB_vertex_attrib_binding spec says:
1770 * "If <buffer> is zero, any buffer object attached to this
1771 * bindpoint is detached."
1773 vbo
= ctx
->Shared
->NullBufferObj
;
1776 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
1777 vbo
, offset
, stride
);
1782 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1785 GET_CURRENT_CONTEXT(ctx
);
1787 /* The ARB_vertex_attrib_binding spec says:
1789 * "An INVALID_OPERATION error is generated if no vertex array object
1792 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
1793 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1794 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1795 "glBindVertexBuffer(No array object bound)");
1799 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
1800 buffer
, offset
, stride
, "glBindVertexBuffer");
1805 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
1806 GLintptr offset
, GLsizei stride
)
1808 GET_CURRENT_CONTEXT(ctx
);
1809 struct gl_vertex_array_object
*vao
;
1811 /* The ARB_direct_state_access specification says:
1813 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1814 * if <vaobj> is not [compatibility profile: zero or] the name of an
1815 * existing vertex array object."
1817 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
1821 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
,
1822 buffer
, offset
, stride
,
1823 "glVertexArrayVertexBuffer");
1828 vertex_array_vertex_buffers(struct gl_context
*ctx
,
1829 struct gl_vertex_array_object
*vao
,
1830 GLuint first
, GLsizei count
, const GLuint
*buffers
,
1831 const GLintptr
*offsets
, const GLsizei
*strides
,
1836 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1838 /* The ARB_multi_bind spec says:
1840 * "An INVALID_OPERATION error is generated if <first> + <count>
1841 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1843 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1844 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1845 "%s(first=%u + count=%d > the value of "
1846 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1847 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1853 * The ARB_multi_bind spec says:
1855 * "If <buffers> is NULL, each affected vertex buffer binding point
1856 * from <first> through <first>+<count>-1 will be reset to have no
1857 * bound buffer object. In this case, the offsets and strides
1858 * associated with the binding points are set to default values,
1859 * ignoring <offsets> and <strides>."
1861 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1863 for (i
= 0; i
< count
; i
++)
1864 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1870 /* Note that the error semantics for multi-bind commands differ from
1871 * those of other GL commands.
1873 * The Issues section in the ARB_multi_bind spec says:
1875 * "(11) Typically, OpenGL specifies that if an error is generated by
1876 * a command, that command has no effect. This is somewhat
1877 * unfortunate for multi-bind commands, because it would require
1878 * a first pass to scan the entire list of bound objects for
1879 * errors and then a second pass to actually perform the
1880 * bindings. Should we have different error semantics?
1882 * RESOLVED: Yes. In this specification, when the parameters for
1883 * one of the <count> binding points are invalid, that binding
1884 * point is not updated and an error will be generated. However,
1885 * other binding points in the same command will be updated if
1886 * their parameters are valid and no other error occurs."
1889 _mesa_begin_bufferobj_lookups(ctx
);
1891 for (i
= 0; i
< count
; i
++) {
1892 struct gl_buffer_object
*vbo
;
1894 /* The ARB_multi_bind spec says:
1896 * "An INVALID_VALUE error is generated if any value in
1897 * <offsets> or <strides> is negative (per binding)."
1899 if (offsets
[i
] < 0) {
1900 _mesa_error(ctx
, GL_INVALID_VALUE
,
1901 "%s(offsets[%u]=%" PRId64
" < 0)",
1902 func
, i
, (int64_t) offsets
[i
]);
1906 if (strides
[i
] < 0) {
1907 _mesa_error(ctx
, GL_INVALID_VALUE
,
1908 "%s(strides[%u]=%d < 0)",
1909 func
, i
, strides
[i
]);
1913 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1914 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
1915 _mesa_error(ctx
, GL_INVALID_VALUE
,
1916 "%s(strides[%u]=%d > "
1917 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
1922 struct gl_vertex_buffer_binding
*binding
=
1923 &vao
->BufferBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1925 if (buffers
[i
] == binding
->BufferObj
->Name
)
1926 vbo
= binding
->BufferObj
;
1928 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
1933 vbo
= ctx
->Shared
->NullBufferObj
;
1936 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1937 vbo
, offsets
[i
], strides
[i
]);
1940 _mesa_end_bufferobj_lookups(ctx
);
1945 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1946 const GLintptr
*offsets
, const GLsizei
*strides
)
1948 GET_CURRENT_CONTEXT(ctx
);
1950 /* The ARB_vertex_attrib_binding spec says:
1952 * "An INVALID_OPERATION error is generated if no
1953 * vertex array object is bound."
1955 if (ctx
->API
== API_OPENGL_CORE
&&
1956 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1957 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1958 "glBindVertexBuffers(No array object bound)");
1962 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
1963 buffers
, offsets
, strides
,
1964 "glBindVertexBuffers");
1969 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
1970 const GLuint
*buffers
,
1971 const GLintptr
*offsets
, const GLsizei
*strides
)
1973 GET_CURRENT_CONTEXT(ctx
);
1974 struct gl_vertex_array_object
*vao
;
1976 /* The ARB_direct_state_access specification says:
1978 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1979 * if <vaobj> is not [compatibility profile: zero or] the name of an
1980 * existing vertex array object."
1982 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
1986 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
1987 buffers
, offsets
, strides
,
1988 "glVertexArrayVertexBuffers");
1993 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
1994 GLboolean normalized
, GLboolean integer
,
1995 GLboolean doubles
, GLbitfield legalTypes
,
1996 GLsizei maxSize
, GLuint relativeOffset
,
1999 GET_CURRENT_CONTEXT(ctx
);
2000 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2002 /* The ARB_vertex_attrib_binding spec says:
2004 * "An INVALID_OPERATION error is generated under any of the following
2006 * - if no vertex array object is currently bound (see section 2.10);
2009 * This error condition only applies to VertexAttribFormat and
2010 * VertexAttribIFormat in the extension spec, but we assume that this
2011 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2012 * to all three functions.
2014 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2015 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2016 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2017 "%s(No array object bound)", func
);
2021 /* The ARB_vertex_attrib_binding spec says:
2023 * "The error INVALID_VALUE is generated if index is greater than or equal
2024 * to the value of MAX_VERTEX_ATTRIBS."
2026 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2027 _mesa_error(ctx
, GL_INVALID_VALUE
,
2028 "%s(attribindex=%u > "
2029 "GL_MAX_VERTEX_ATTRIBS)",
2034 FLUSH_VERTICES(ctx
, 0);
2036 update_array_format(ctx
, func
, ctx
->Array
.VAO
,
2037 VERT_ATTRIB_GENERIC(attribIndex
),
2038 legalTypes
, 1, maxSize
, size
, type
,
2039 normalized
, integer
, doubles
, relativeOffset
);
2044 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2045 GLboolean normalized
, GLuint relativeOffset
)
2047 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
2048 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2049 BGRA_OR_4
, relativeOffset
,
2050 "glVertexAttribFormat");
2055 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2056 GLuint relativeOffset
)
2058 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
2059 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
2060 relativeOffset
, "glVertexAttribIFormat");
2065 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2066 GLuint relativeOffset
)
2068 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
2069 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
2070 relativeOffset
, "glVertexAttribLFormat");
2075 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2076 GLenum type
, GLboolean normalized
,
2077 GLboolean integer
, GLboolean doubles
,
2078 GLbitfield legalTypes
, GLsizei maxSize
,
2079 GLuint relativeOffset
, const char *func
)
2081 GET_CURRENT_CONTEXT(ctx
);
2082 struct gl_vertex_array_object
*vao
;
2084 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2086 /* The ARB_direct_state_access spec says:
2088 * "An INVALID_OPERATION error is generated by VertexArrayAttrib*Format
2089 * if <vaobj> is not [compatibility profile: zero or] the name of an
2090 * existing vertex array object."
2092 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
2096 /* The ARB_vertex_attrib_binding spec says:
2098 * "The error INVALID_VALUE is generated if index is greater than or equal
2099 * to the value of MAX_VERTEX_ATTRIBS."
2101 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2102 _mesa_error(ctx
, GL_INVALID_VALUE
,
2103 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2108 FLUSH_VERTICES(ctx
, 0);
2110 update_array_format(ctx
, func
, vao
,
2111 VERT_ATTRIB_GENERIC(attribIndex
),
2112 legalTypes
, 1, maxSize
, size
, type
, normalized
,
2113 integer
, doubles
, relativeOffset
);
2118 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2119 GLenum type
, GLboolean normalized
,
2120 GLuint relativeOffset
)
2122 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
2123 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2124 BGRA_OR_4
, relativeOffset
,
2125 "glVertexArrayAttribFormat");
2130 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
2131 GLint size
, GLenum type
,
2132 GLuint relativeOffset
)
2134 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2135 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
2137 "glVertexArrayAttribIFormat");
2142 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
2143 GLint size
, GLenum type
,
2144 GLuint relativeOffset
)
2146 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2147 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
2149 "glVertexArrayAttribLFormat");
2154 vertex_array_attrib_binding(struct gl_context
*ctx
,
2155 struct gl_vertex_array_object
*vao
,
2156 GLuint attribIndex
, GLuint bindingIndex
,
2159 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2161 /* The ARB_vertex_attrib_binding spec says:
2163 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2164 * <bindingindex> must be less than the value of
2165 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2168 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2169 _mesa_error(ctx
, GL_INVALID_VALUE
,
2170 "%s(attribindex=%u >= "
2171 "GL_MAX_VERTEX_ATTRIBS)",
2176 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2177 _mesa_error(ctx
, GL_INVALID_VALUE
,
2178 "%s(bindingindex=%u >= "
2179 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2180 func
, bindingIndex
);
2184 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
2186 vertex_attrib_binding(ctx
, vao
,
2187 VERT_ATTRIB_GENERIC(attribIndex
),
2188 VERT_ATTRIB_GENERIC(bindingIndex
));
2193 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2195 GET_CURRENT_CONTEXT(ctx
);
2197 /* The ARB_vertex_attrib_binding spec says:
2199 * "An INVALID_OPERATION error is generated if no vertex array object
2202 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2203 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2204 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2205 "glVertexAttribBinding(No array object bound)");
2209 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2210 attribIndex
, bindingIndex
,
2211 "glVertexAttribBinding");
2216 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2218 GET_CURRENT_CONTEXT(ctx
);
2219 struct gl_vertex_array_object
*vao
;
2221 /* The ARB_direct_state_access specification says:
2223 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2224 * if <vaobj> is not [compatibility profile: zero or] the name of an
2225 * existing vertex array object."
2227 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2231 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2232 "glVertexArrayAttribBinding");
2237 vertex_array_binding_divisor(struct gl_context
*ctx
,
2238 struct gl_vertex_array_object
*vao
,
2239 GLuint bindingIndex
, GLuint divisor
,
2242 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2244 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2245 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
2249 /* The ARB_vertex_attrib_binding spec says:
2251 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2252 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2254 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2255 _mesa_error(ctx
, GL_INVALID_VALUE
,
2256 "%s(bindingindex=%u > "
2257 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2258 func
, bindingIndex
);
2262 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2267 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2269 GET_CURRENT_CONTEXT(ctx
);
2271 /* The ARB_vertex_attrib_binding spec says:
2273 * "An INVALID_OPERATION error is generated if no vertex array object
2276 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2277 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2278 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2279 "glVertexBindingDivisor(No array object bound)");
2283 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
2284 bindingIndex
, divisor
,
2285 "glVertexBindingDivisor");
2290 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
2293 struct gl_vertex_array_object
*vao
;
2294 GET_CURRENT_CONTEXT(ctx
);
2296 /* The ARB_direct_state_access specification says:
2298 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2299 * if <vaobj> is not [compatibility profile: zero or] the name of an
2300 * existing vertex array object."
2302 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayBindingDivisor");
2306 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
2307 "glVertexArrayBindingDivisor");
2312 * Copy one client vertex array to another.
2315 _mesa_copy_client_array(struct gl_context
*ctx
,
2316 struct gl_vertex_array
*dst
,
2317 struct gl_vertex_array
*src
)
2319 dst
->Size
= src
->Size
;
2320 dst
->Type
= src
->Type
;
2321 dst
->Format
= src
->Format
;
2322 dst
->StrideB
= src
->StrideB
;
2323 dst
->Ptr
= src
->Ptr
;
2324 dst
->Normalized
= src
->Normalized
;
2325 dst
->Integer
= src
->Integer
;
2326 dst
->Doubles
= src
->Doubles
;
2327 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2328 dst
->_ElementSize
= src
->_ElementSize
;
2329 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2333 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2334 struct gl_array_attributes
*dst
,
2335 const struct gl_array_attributes
*src
)
2337 dst
->Size
= src
->Size
;
2338 dst
->Type
= src
->Type
;
2339 dst
->Format
= src
->Format
;
2340 dst
->BufferBindingIndex
= src
->BufferBindingIndex
;
2341 dst
->RelativeOffset
= src
->RelativeOffset
;
2342 dst
->Format
= src
->Format
;
2343 dst
->Integer
= src
->Integer
;
2344 dst
->Doubles
= src
->Doubles
;
2345 dst
->Normalized
= src
->Normalized
;
2346 dst
->Ptr
= src
->Ptr
;
2347 dst
->Enabled
= src
->Enabled
;
2348 dst
->_ElementSize
= src
->_ElementSize
;
2352 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2353 struct gl_vertex_buffer_binding
*dst
,
2354 const struct gl_vertex_buffer_binding
*src
)
2356 dst
->Offset
= src
->Offset
;
2357 dst
->Stride
= src
->Stride
;
2358 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2359 dst
->_BoundArrays
= src
->_BoundArrays
;
2361 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2365 * Print current vertex object/array info. For debug.
2368 _mesa_print_arrays(struct gl_context
*ctx
)
2370 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2372 fprintf(stderr
, "Array Object %u\n", vao
->Name
);
2375 for (i
= 0; i
< VERT_ATTRIB_MAX
; ++i
) {
2376 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
2377 if (!array
->Enabled
)
2380 const struct gl_vertex_buffer_binding
*binding
=
2381 &vao
->BufferBinding
[array
->BufferBindingIndex
];
2382 const struct gl_buffer_object
*bo
= binding
->BufferObj
;
2384 fprintf(stderr
, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
2385 "Stride=%d, Buffer=%u(Size %lu)\n",
2386 gl_vert_attrib_name((gl_vert_attrib
)i
),
2387 array
->Ptr
, _mesa_enum_to_string(array
->Type
), array
->Size
,
2388 array
->_ElementSize
, binding
->Stride
, bo
->Name
,
2389 (unsigned long) bo
->Size
);
2395 * Initialize vertex array state for given context.
2398 _mesa_init_varray(struct gl_context
*ctx
)
2400 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
2401 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2402 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2404 ctx
->Array
.Objects
= _mesa_NewHashTable();
2409 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2412 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2414 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2415 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2416 _mesa_delete_vao(ctx
, vao
);
2421 * Free vertex array state for given context.
2424 _mesa_free_varray_data(struct gl_context
*ctx
)
2426 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2427 _mesa_DeleteHashTable(ctx
->Array
.Objects
);