2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
28 #include <inttypes.h> /* for PRId64 macro */
32 #include "bufferobj.h"
42 #include "main/dispatch.h"
45 /** Used to do error checking for GL_EXT_vertex_array_bgra */
49 /** Used to indicate which GL datatypes are accepted by each of the
50 * glVertex/Color/Attrib/EtcPointer() functions.
52 #define BOOL_BIT (1 << 0)
53 #define BYTE_BIT (1 << 1)
54 #define UNSIGNED_BYTE_BIT (1 << 2)
55 #define SHORT_BIT (1 << 3)
56 #define UNSIGNED_SHORT_BIT (1 << 4)
57 #define INT_BIT (1 << 5)
58 #define UNSIGNED_INT_BIT (1 << 6)
59 #define HALF_BIT (1 << 7)
60 #define FLOAT_BIT (1 << 8)
61 #define DOUBLE_BIT (1 << 9)
62 #define FIXED_ES_BIT (1 << 10)
63 #define FIXED_GL_BIT (1 << 11)
64 #define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12)
65 #define INT_2_10_10_10_REV_BIT (1 << 13)
66 #define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)
67 #define ALL_TYPE_BITS ((1 << 15) - 1)
69 #define ATTRIB_FORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
70 SHORT_BIT | UNSIGNED_SHORT_BIT | \
71 INT_BIT | UNSIGNED_INT_BIT | \
72 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | \
74 UNSIGNED_INT_2_10_10_10_REV_BIT | \
75 INT_2_10_10_10_REV_BIT | \
76 UNSIGNED_INT_10F_11F_11F_REV_BIT)
78 #define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
79 SHORT_BIT | UNSIGNED_SHORT_BIT | \
80 INT_BIT | UNSIGNED_INT_BIT)
82 #define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT
85 /** Convert GL datatype enum into a <type>_BIT value seen above */
87 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
94 case GL_UNSIGNED_BYTE
:
95 return UNSIGNED_BYTE_BIT
;
98 case GL_UNSIGNED_SHORT
:
99 return UNSIGNED_SHORT_BIT
;
102 case GL_UNSIGNED_INT
:
103 return UNSIGNED_INT_BIT
;
105 if (ctx
->Extensions
.ARB_half_float_vertex
)
114 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
115 case GL_UNSIGNED_INT_2_10_10_10_REV
:
116 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
117 case GL_INT_2_10_10_10_REV
:
118 return INT_2_10_10_10_REV_BIT
;
119 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
120 return UNSIGNED_INT_10F_11F_11F_REV_BIT
;
128 * Sets the VertexBinding field in the vertex attribute given by attribIndex.
131 vertex_attrib_binding(struct gl_context
*ctx
, GLuint attribIndex
,
134 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
135 struct gl_vertex_attrib_array
*array
= &vao
->VertexAttrib
[attribIndex
];
137 if (array
->VertexBinding
!= bindingIndex
) {
138 const GLbitfield64 array_bit
= VERT_BIT(attribIndex
);
140 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
142 vao
->VertexBinding
[array
->VertexBinding
]._BoundArrays
&= ~array_bit
;
143 vao
->VertexBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
145 array
->VertexBinding
= bindingIndex
;
147 vao
->NewArrays
|= array_bit
;
153 * Binds a buffer object to the vertex buffer binding point given by index,
154 * and sets the Offset and Stride fields.
157 bind_vertex_buffer(struct gl_context
*ctx
,
158 struct gl_vertex_array_object
*vao
,
160 struct gl_buffer_object
*vbo
,
161 GLintptr offset
, GLsizei stride
)
163 struct gl_vertex_buffer_binding
*binding
= &vao
->VertexBinding
[index
];
165 if (binding
->BufferObj
!= vbo
||
166 binding
->Offset
!= offset
||
167 binding
->Stride
!= stride
) {
169 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
171 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
173 binding
->Offset
= offset
;
174 binding
->Stride
= stride
;
176 vao
->NewArrays
|= binding
->_BoundArrays
;
182 * Sets the InstanceDivisor field in the vertex buffer binding point
183 * given by bindingIndex.
186 vertex_binding_divisor(struct gl_context
*ctx
, GLuint bindingIndex
,
189 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
190 struct gl_vertex_buffer_binding
*binding
=
191 &vao
->VertexBinding
[bindingIndex
];
193 if (binding
->InstanceDivisor
!= divisor
) {
194 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
195 binding
->InstanceDivisor
= divisor
;
196 vao
->NewArrays
|= binding
->_BoundArrays
;
202 * Examine the API profile and extensions to determine which types are legal
203 * for vertex arrays. This is called once from update_array_format().
206 get_legal_types_mask(const struct gl_context
*ctx
)
208 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
210 if (_mesa_is_gles(ctx
)) {
211 legalTypesMask
&= ~(FIXED_GL_BIT
|
213 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
215 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
216 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
217 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
218 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
219 * quite as trivial as we'd like because it uses a different enum value
220 * for GL_HALF_FLOAT_OES.
222 if (ctx
->Version
< 30) {
223 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
225 UNSIGNED_INT_2_10_10_10_REV_BIT
|
226 INT_2_10_10_10_REV_BIT
|
231 legalTypesMask
&= ~FIXED_ES_BIT
;
233 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
234 legalTypesMask
&= ~FIXED_GL_BIT
;
236 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
237 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
238 INT_2_10_10_10_REV_BIT
);
240 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
241 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
244 return legalTypesMask
;
249 * Does error checking and updates the format in an attrib array.
251 * Called by update_array() and VertexAttrib*Format().
253 * \param func Name of calling function used for error reporting
254 * \param attrib The index of the attribute array
255 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
256 * \param sizeMin Min allowable size value
257 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
258 * \param size Components per element (1, 2, 3 or 4)
259 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
260 * \param normalized Whether integer types are converted to floats in [-1, 1]
261 * \param integer Integer-valued values (will not be normalized to [-1, 1])
262 * \param doubles Double values not reduced to floats
263 * \param relativeOffset Offset of the first element relative to the binding offset.
266 update_array_format(struct gl_context
*ctx
,
268 GLuint attrib
, GLbitfield legalTypesMask
,
269 GLint sizeMin
, GLint sizeMax
,
270 GLint size
, GLenum type
,
271 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
272 GLuint relativeOffset
)
274 struct gl_vertex_attrib_array
*array
;
277 GLenum format
= GL_RGBA
;
279 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
280 /* Compute the LegalTypesMask only once, unless the context API has
281 * changed, in which case we want to compute it again. We can't do this
282 * in _mesa_init_varrays() below because extensions are not yet enabled
285 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
286 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
289 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
291 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
292 /* BGRA ordering is not supported in ES contexts.
297 typeBit
= type_to_bit(ctx
, type
);
298 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
299 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
300 func
, _mesa_lookup_enum_by_nr(type
));
304 /* Do size parameter checking.
305 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
306 * must be handled specially.
308 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
309 sizeMax
== BGRA_OR_4
&&
311 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
313 * "An INVALID_OPERATION error is generated under any of the following
316 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
317 * or UNSIGNED_INT_2_10_10_10_REV;
319 * • size is BGRA and normalized is FALSE;"
321 bool bgra_error
= false;
323 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
324 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
325 type
!= GL_INT_2_10_10_10_REV
&&
326 type
!= GL_UNSIGNED_BYTE
)
328 } else if (type
!= GL_UNSIGNED_BYTE
)
332 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
333 func
, _mesa_lookup_enum_by_nr(type
));
338 _mesa_error(ctx
, GL_INVALID_OPERATION
,
339 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
346 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
347 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
351 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
352 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
353 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
354 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
358 /* The ARB_vertex_attrib_binding_spec says:
360 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
361 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
363 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
364 _mesa_error(ctx
, GL_INVALID_VALUE
,
365 "%s(relativeOffset=%d > "
366 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
367 func
, relativeOffset
);
371 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
372 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
373 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
379 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
380 assert(elementSize
!= -1);
382 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
385 array
->Format
= format
;
386 array
->Normalized
= normalized
;
387 array
->Integer
= integer
;
388 array
->Doubles
= doubles
;
389 array
->RelativeOffset
= relativeOffset
;
390 array
->_ElementSize
= elementSize
;
392 ctx
->Array
.VAO
->NewArrays
|= VERT_BIT(attrib
);
393 ctx
->NewState
|= _NEW_ARRAY
;
400 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
403 * \param func name of calling function used for error reporting
404 * \param attrib the attribute array index to update
405 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
406 * \param sizeMin min allowable size value
407 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
408 * \param size components per element (1, 2, 3 or 4)
409 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
410 * \param stride stride between elements, in elements
411 * \param normalized are integer types converted to floats in [-1, 1]?
412 * \param integer integer-valued values (will not be normalized to [-1,1])
413 * \param doubles Double values not reduced to floats
414 * \param ptr the address (or offset inside VBO) of the array data
417 update_array(struct gl_context
*ctx
,
419 GLuint attrib
, GLbitfield legalTypesMask
,
420 GLint sizeMin
, GLint sizeMax
,
421 GLint size
, GLenum type
, GLsizei stride
,
422 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
425 struct gl_vertex_attrib_array
*array
;
426 GLsizei effectiveStride
;
428 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
430 * "Client vertex arrays - all vertex array attribute pointers must
431 * refer to buffer objects (section 2.9.2). The default vertex array
432 * object (the name zero) is also deprecated. Calling
433 * VertexAttribPointer when no buffer object or no vertex array object
434 * is bound will generate an INVALID_OPERATION error..."
436 * The check for VBOs is handled below.
438 if (ctx
->API
== API_OPENGL_CORE
439 && (ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
)) {
440 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
446 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
450 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
451 stride
> ctx
->Const
.MaxVertexAttribStride
) {
452 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
453 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
457 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
459 * "An INVALID_OPERATION error is generated under any of the following
464 * * any of the *Pointer commands specifying the location and
465 * organization of vertex array data are called while zero is bound
466 * to the ARRAY_BUFFER buffer object binding point (see section
467 * 2.9.6), and the pointer argument is not NULL."
469 if (ptr
!= NULL
&& ctx
->Array
.VAO
->ARBsemantics
&&
470 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
471 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
475 if (!update_array_format(ctx
, func
, attrib
, legalTypesMask
, sizeMin
,
476 sizeMax
, size
, type
, normalized
, integer
, doubles
, 0)) {
480 /* Reset the vertex attrib binding */
481 vertex_attrib_binding(ctx
, attrib
, attrib
);
483 /* The Stride and Ptr fields are not set by update_array_format() */
484 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
485 array
->Stride
= stride
;
486 array
->Ptr
= (const GLvoid
*) ptr
;
488 /* Update the vertex buffer binding */
489 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
490 bind_vertex_buffer(ctx
, ctx
->Array
.VAO
, attrib
, ctx
->Array
.ArrayBufferObj
,
491 (GLintptr
) ptr
, effectiveStride
);
496 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
498 GET_CURRENT_CONTEXT(ctx
);
499 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
500 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
501 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
502 DOUBLE_BIT
| HALF_BIT
|
503 UNSIGNED_INT_2_10_10_10_REV_BIT
|
504 INT_2_10_10_10_REV_BIT
);
506 FLUSH_VERTICES(ctx
, 0);
508 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
510 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
515 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
517 GET_CURRENT_CONTEXT(ctx
);
518 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
519 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
520 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
521 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
522 UNSIGNED_INT_2_10_10_10_REV_BIT
|
523 INT_2_10_10_10_REV_BIT
);
525 FLUSH_VERTICES(ctx
, 0);
527 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
529 3, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
534 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
536 GET_CURRENT_CONTEXT(ctx
);
537 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
538 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
539 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
540 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
541 INT_BIT
| UNSIGNED_INT_BIT
|
542 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
543 UNSIGNED_INT_2_10_10_10_REV_BIT
|
544 INT_2_10_10_10_REV_BIT
);
545 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
547 FLUSH_VERTICES(ctx
, 0);
549 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
550 legalTypes
, sizeMin
, BGRA_OR_4
,
551 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
556 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
558 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
559 GET_CURRENT_CONTEXT(ctx
);
561 FLUSH_VERTICES(ctx
, 0);
563 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
565 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
570 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
572 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
573 FLOAT_BIT
| DOUBLE_BIT
);
574 GET_CURRENT_CONTEXT(ctx
);
576 FLUSH_VERTICES(ctx
, 0);
578 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
580 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
585 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
586 GLsizei stride
, const GLvoid
*ptr
)
588 const GLbitfield legalTypes
= (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 GET_CURRENT_CONTEXT(ctx
);
596 FLUSH_VERTICES(ctx
, 0);
598 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
599 legalTypes
, 3, BGRA_OR_4
,
600 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
605 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
608 GET_CURRENT_CONTEXT(ctx
);
609 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
610 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
611 : (SHORT_BIT
| INT_BIT
|
612 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
613 UNSIGNED_INT_2_10_10_10_REV_BIT
|
614 INT_2_10_10_10_REV_BIT
);
615 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
616 const GLuint unit
= ctx
->Array
.ActiveTexture
;
618 FLUSH_VERTICES(ctx
, 0);
620 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
621 legalTypes
, sizeMin
, 4,
622 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
628 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
630 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
631 /* this is the same type that glEdgeFlag uses */
632 const GLboolean integer
= GL_FALSE
;
633 GET_CURRENT_CONTEXT(ctx
);
635 FLUSH_VERTICES(ctx
, 0);
637 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
639 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
644 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
646 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
647 GET_CURRENT_CONTEXT(ctx
);
649 FLUSH_VERTICES(ctx
, 0);
651 if (ctx
->API
!= API_OPENGLES
) {
652 _mesa_error(ctx
, GL_INVALID_OPERATION
,
653 "glPointSizePointer(ES 1.x only)");
657 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
659 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
664 * Set a generic vertex attribute array.
665 * Note that these arrays DO NOT alias the conventional GL vertex arrays
666 * (position, normal, color, fog, texcoord, etc).
669 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
670 GLboolean normalized
,
671 GLsizei stride
, const GLvoid
*ptr
)
673 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
674 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
675 INT_BIT
| UNSIGNED_INT_BIT
|
676 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
677 FIXED_ES_BIT
| FIXED_GL_BIT
|
678 UNSIGNED_INT_2_10_10_10_REV_BIT
|
679 INT_2_10_10_10_REV_BIT
|
680 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
681 GET_CURRENT_CONTEXT(ctx
);
683 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
684 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
688 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
689 legalTypes
, 1, BGRA_OR_4
,
690 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
695 * GL_EXT_gpu_shader4 / GL 3.0.
696 * Set an integer-valued vertex attribute array.
697 * Note that these arrays DO NOT alias the conventional GL vertex arrays
698 * (position, normal, color, fog, texcoord, etc).
701 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
702 GLsizei stride
, const GLvoid
*ptr
)
704 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
705 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
706 INT_BIT
| UNSIGNED_INT_BIT
);
707 const GLboolean normalized
= GL_FALSE
;
708 const GLboolean integer
= GL_TRUE
;
709 GET_CURRENT_CONTEXT(ctx
);
711 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
712 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
716 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
718 size
, type
, stride
, normalized
, integer
, GL_FALSE
, ptr
);
722 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
723 GLsizei stride
, const GLvoid
*ptr
)
725 GET_CURRENT_CONTEXT(ctx
);
726 const GLbitfield legalTypes
= (DOUBLE_BIT
);
727 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
728 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
732 update_array(ctx
, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index
),
734 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_TRUE
, ptr
);
739 enable_vertex_array_attrib(struct gl_context
*ctx
,
740 struct gl_vertex_array_object
*vao
,
744 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
745 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
749 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
751 if (!vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
752 /* was disabled, now being enabled */
753 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
754 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
755 vao
->_Enabled
|= VERT_BIT_GENERIC(index
);
756 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
762 _mesa_EnableVertexAttribArray(GLuint index
)
764 GET_CURRENT_CONTEXT(ctx
);
765 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
766 "glEnableVertexAttribArray");
771 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
773 GET_CURRENT_CONTEXT(ctx
);
774 struct gl_vertex_array_object
*vao
;
776 /* The ARB_direct_state_access specification says:
778 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
779 * and DisableVertexArrayAttrib if <vaobj> is not
780 * [compatibility profile: zero or] the name of an existing vertex
783 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
787 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
792 disable_vertex_array_attrib(struct gl_context
*ctx
,
793 struct gl_vertex_array_object
*vao
,
797 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
798 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
802 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
804 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
805 /* was enabled, now being disabled */
806 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
807 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
808 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
809 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
815 _mesa_DisableVertexAttribArray(GLuint index
)
817 GET_CURRENT_CONTEXT(ctx
);
818 disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
819 "glDisableVertexAttribArray");
824 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
826 GET_CURRENT_CONTEXT(ctx
);
827 struct gl_vertex_array_object
*vao
;
829 /* The ARB_direct_state_access specification says:
831 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
832 * and DisableVertexArrayAttrib if <vaobj> is not
833 * [compatibility profile: zero or] the name of an existing vertex
836 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
840 disable_vertex_array_attrib(ctx
, vao
, index
, "glDisableVertexArrayAttrib");
845 * Return info for a vertex attribute array (no alias with legacy
846 * vertex attributes (pos, normal, color, etc)). This function does
847 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
850 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
853 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
854 const struct gl_vertex_attrib_array
*array
;
856 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
857 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
861 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
863 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
866 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
867 return array
->Enabled
;
868 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
869 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
870 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
871 return array
->Stride
;
872 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
874 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
875 return array
->Normalized
;
876 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
877 return vao
->VertexBinding
[array
->VertexBinding
].BufferObj
->Name
;
878 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
879 if ((_mesa_is_desktop_gl(ctx
)
880 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
881 || _mesa_is_gles3(ctx
)) {
882 return array
->Integer
;
885 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
886 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
887 || _mesa_is_gles3(ctx
)) {
888 return vao
->VertexBinding
[array
->VertexBinding
].InstanceDivisor
;
891 case GL_VERTEX_ATTRIB_BINDING
:
892 if (_mesa_is_desktop_gl(ctx
)) {
893 return array
->VertexBinding
- VERT_ATTRIB_GENERIC0
;
896 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
897 if (_mesa_is_desktop_gl(ctx
)) {
898 return array
->RelativeOffset
;
906 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
911 static const GLfloat
*
912 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
915 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
916 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
920 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
921 _mesa_error(ctx
, GL_INVALID_VALUE
,
922 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
926 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
928 FLUSH_CURRENT(ctx
, 0);
929 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
933 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
935 GET_CURRENT_CONTEXT(ctx
);
937 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
938 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
944 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
945 "glGetVertexAttribfv");
951 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
953 GET_CURRENT_CONTEXT(ctx
);
955 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
956 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
958 params
[0] = (GLdouble
) v
[0];
959 params
[1] = (GLdouble
) v
[1];
960 params
[2] = (GLdouble
) v
[2];
961 params
[3] = (GLdouble
) v
[3];
965 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
966 "glGetVertexAttribdv");
971 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
973 GET_CURRENT_CONTEXT(ctx
);
975 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
976 const GLdouble
*v
= (const GLdouble
*)get_current_attrib(ctx
, index
, "glGetVertexAttribLdv");
985 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
986 "glGetVertexAttribLdv");
991 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
993 GET_CURRENT_CONTEXT(ctx
);
995 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
996 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
998 /* XXX should floats in[0,1] be scaled to full int range? */
999 params
[0] = (GLint
) v
[0];
1000 params
[1] = (GLint
) v
[1];
1001 params
[2] = (GLint
) v
[2];
1002 params
[3] = (GLint
) v
[3];
1006 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
1007 "glGetVertexAttribiv");
1014 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1016 GET_CURRENT_CONTEXT(ctx
);
1018 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1019 const GLint
*v
= (const GLint
*)
1020 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1026 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
1027 "glGetVertexAttribIiv");
1034 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1036 GET_CURRENT_CONTEXT(ctx
);
1038 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1039 const GLuint
*v
= (const GLuint
*)
1040 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1046 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
1047 "glGetVertexAttribIuiv");
1053 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1055 GET_CURRENT_CONTEXT(ctx
);
1057 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1058 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1062 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1063 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1067 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1069 *pointer
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1074 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1075 GLsizei count
, const GLvoid
*ptr
)
1078 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1083 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1087 _mesa_NormalPointer(type
, stride
, ptr
);
1092 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1096 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1101 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1105 _mesa_IndexPointer(type
, stride
, ptr
);
1110 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1111 GLsizei count
, const GLvoid
*ptr
)
1114 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1119 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1122 _mesa_EdgeFlagPointer(stride
, ptr
);
1127 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1129 GET_CURRENT_CONTEXT(ctx
);
1130 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1131 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1132 GLenum ctype
= 0; /* color type */
1133 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1134 const GLint toffset
= 0; /* always zero */
1135 GLint defstride
; /* default stride */
1138 FLUSH_VERTICES(ctx
, 0);
1140 f
= sizeof(GLfloat
);
1141 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1144 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1150 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1151 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1156 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1157 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1162 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1163 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1164 ctype
= GL_UNSIGNED_BYTE
;
1167 defstride
= c
+ 2*f
;
1170 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1171 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1172 ctype
= GL_UNSIGNED_BYTE
;
1175 defstride
= c
+ 3*f
;
1178 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1179 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1186 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1187 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1192 case GL_C4F_N3F_V3F
:
1193 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1194 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1202 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1203 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1208 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1209 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1213 case GL_T2F_C4UB_V3F
:
1214 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1215 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1216 ctype
= GL_UNSIGNED_BYTE
;
1221 case GL_T2F_C3F_V3F
:
1222 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1223 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1229 case GL_T2F_N3F_V3F
:
1230 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1231 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1236 case GL_T2F_C4F_N3F_V3F
:
1237 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1238 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1245 case GL_T4F_C4F_N3F_V4F
:
1246 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1247 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1255 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1263 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1264 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1265 /* XXX also disable secondary color and generic arrays? */
1269 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1270 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1271 (GLubyte
*) pointer
+ toffset
);
1274 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1279 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1280 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1281 (GLubyte
*) pointer
+ coffset
);
1284 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1290 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1291 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1294 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1298 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1299 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1300 (GLubyte
*) pointer
+ voffset
);
1305 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1307 GET_CURRENT_CONTEXT(ctx
);
1309 FLUSH_VERTICES(ctx
, 0);
1311 if (MESA_VERBOSE
& VERBOSE_API
)
1312 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1315 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1319 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1322 if (ctx
->Array
.LockCount
!= 0) {
1323 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1327 ctx
->Array
.LockFirst
= first
;
1328 ctx
->Array
.LockCount
= count
;
1330 ctx
->NewState
|= _NEW_ARRAY
;
1335 _mesa_UnlockArraysEXT( void )
1337 GET_CURRENT_CONTEXT(ctx
);
1339 FLUSH_VERTICES(ctx
, 0);
1341 if (MESA_VERBOSE
& VERBOSE_API
)
1342 _mesa_debug(ctx
, "glUnlockArrays\n");
1344 if (ctx
->Array
.LockCount
== 0) {
1345 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1349 ctx
->Array
.LockFirst
= 0;
1350 ctx
->Array
.LockCount
= 0;
1351 ctx
->NewState
|= _NEW_ARRAY
;
1355 /* GL_EXT_multi_draw_arrays */
1357 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1358 const GLsizei
*count
, GLsizei primcount
)
1360 GET_CURRENT_CONTEXT(ctx
);
1363 FLUSH_VERTICES(ctx
, 0);
1365 for (i
= 0; i
< primcount
; i
++) {
1367 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1373 /* GL_IBM_multimode_draw_arrays */
1375 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1376 const GLsizei
* count
,
1377 GLsizei primcount
, GLint modestride
)
1379 GET_CURRENT_CONTEXT(ctx
);
1382 FLUSH_VERTICES(ctx
, 0);
1384 for ( i
= 0 ; i
< primcount
; i
++ ) {
1385 if ( count
[i
] > 0 ) {
1386 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1387 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1393 /* GL_IBM_multimode_draw_arrays */
1395 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1396 GLenum type
, const GLvoid
* const * indices
,
1397 GLsizei primcount
, GLint modestride
)
1399 GET_CURRENT_CONTEXT(ctx
);
1402 FLUSH_VERTICES(ctx
, 0);
1404 /* XXX not sure about ARB_vertex_buffer_object handling here */
1406 for ( i
= 0 ; i
< primcount
; i
++ ) {
1407 if ( count
[i
] > 0 ) {
1408 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1409 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1417 * GL_NV_primitive_restart and GL 3.1
1420 _mesa_PrimitiveRestartIndex(GLuint index
)
1422 GET_CURRENT_CONTEXT(ctx
);
1424 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1425 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1429 if (ctx
->Array
.RestartIndex
!= index
) {
1430 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1431 ctx
->Array
.RestartIndex
= index
;
1437 * See GL_ARB_instanced_arrays.
1438 * Note that the instance divisor only applies to generic arrays, not
1439 * the legacy vertex arrays.
1442 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1444 GET_CURRENT_CONTEXT(ctx
);
1446 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1448 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1449 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1453 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1454 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1459 assert(genericIndex
< ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1461 /* The ARB_vertex_attrib_binding spec says:
1465 * void VertexAttribDivisor(uint index, uint divisor);
1467 * is equivalent to (assuming no errors are generated):
1469 * VertexAttribBinding(index, index);
1470 * VertexBindingDivisor(index, divisor);"
1472 vertex_attrib_binding(ctx
, genericIndex
, genericIndex
);
1473 vertex_binding_divisor(ctx
, genericIndex
, divisor
);
1478 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1480 /* From the OpenGL 4.3 core specification, page 302:
1481 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1482 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1485 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1487 case GL_UNSIGNED_BYTE
:
1489 case GL_UNSIGNED_SHORT
:
1491 case GL_UNSIGNED_INT
:
1494 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1498 return ctx
->Array
.RestartIndex
;
1503 * GL_ARB_vertex_attrib_binding
1506 vertex_array_vertex_buffer(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
,
1507 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1508 GLsizei stride
, const char *func
)
1510 struct gl_buffer_object
*vbo
;
1512 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1514 /* The ARB_vertex_attrib_binding spec says:
1516 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1517 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1519 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1520 _mesa_error(ctx
, GL_INVALID_VALUE
,
1521 "%s(bindingindex=%u > "
1522 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1523 func
, bindingIndex
);
1527 /* The ARB_vertex_attrib_binding spec says:
1529 * "The error INVALID_VALUE is generated if <stride> or <offset>
1533 _mesa_error(ctx
, GL_INVALID_VALUE
,
1534 "%s(offset=%" PRId64
" < 0)",
1535 func
, (int64_t) offset
);
1540 _mesa_error(ctx
, GL_INVALID_VALUE
,
1541 "%s(stride=%d < 0)", func
, stride
);
1545 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1546 stride
> ctx
->Const
.MaxVertexAttribStride
) {
1547 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
1548 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
1552 if (buffer
== vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1553 vbo
= vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1554 } else if (buffer
!= 0) {
1555 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1557 /* From the GL_ARB_vertex_attrib_array spec:
1559 * "[Core profile only:]
1560 * An INVALID_OPERATION error is generated if buffer is not zero or a
1561 * name returned from a previous call to GenBuffers, or if such a name
1562 * has since been deleted with DeleteBuffers.
1564 * Otherwise, we fall back to the same compat profile behavior as other
1565 * object references (automatically gen it).
1567 if (!_mesa_handle_bind_buffer_gen(ctx
, GL_ARRAY_BUFFER
, buffer
,
1571 /* The ARB_vertex_attrib_binding spec says:
1573 * "If <buffer> is zero, any buffer object attached to this
1574 * bindpoint is detached."
1576 vbo
= ctx
->Shared
->NullBufferObj
;
1579 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
1580 vbo
, offset
, stride
);
1585 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1588 GET_CURRENT_CONTEXT(ctx
);
1590 /* The ARB_vertex_attrib_binding spec says:
1592 * "An INVALID_OPERATION error is generated if no vertex array object
1595 if (ctx
->API
== API_OPENGL_CORE
&&
1596 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1597 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1598 "glBindVertexBuffer(No array object bound)");
1602 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
1603 buffer
, offset
, stride
, "glBindVertexBuffer");
1608 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
1609 GLintptr offset
, GLsizei stride
)
1611 GET_CURRENT_CONTEXT(ctx
);
1612 struct gl_vertex_array_object
*vao
;
1614 /* The ARB_direct_state_access specification says:
1616 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1617 * if <vaobj> is not [compatibility profile: zero or] the name of an
1618 * existing vertex array object."
1620 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
1624 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
,
1625 buffer
, offset
, stride
,
1626 "glVertexArrayVertexBuffer");
1631 vertex_array_vertex_buffers(struct gl_context
*ctx
,
1632 struct gl_vertex_array_object
*vao
,
1633 GLuint first
, GLsizei count
, const GLuint
*buffers
,
1634 const GLintptr
*offsets
, const GLsizei
*strides
,
1639 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1641 /* The ARB_multi_bind spec says:
1643 * "An INVALID_OPERATION error is generated if <first> + <count>
1644 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1646 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1647 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1648 "%s(first=%u + count=%d > the value of "
1649 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1650 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1656 * The ARB_multi_bind spec says:
1658 * "If <buffers> is NULL, each affected vertex buffer binding point
1659 * from <first> through <first>+<count>-1 will be reset to have no
1660 * bound buffer object. In this case, the offsets and strides
1661 * associated with the binding points are set to default values,
1662 * ignoring <offsets> and <strides>."
1664 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1666 for (i
= 0; i
< count
; i
++)
1667 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1673 /* Note that the error semantics for multi-bind commands differ from
1674 * those of other GL commands.
1676 * The Issues section in the ARB_multi_bind spec says:
1678 * "(11) Typically, OpenGL specifies that if an error is generated by
1679 * a command, that command has no effect. This is somewhat
1680 * unfortunate for multi-bind commands, because it would require
1681 * a first pass to scan the entire list of bound objects for
1682 * errors and then a second pass to actually perform the
1683 * bindings. Should we have different error semantics?
1685 * RESOLVED: Yes. In this specification, when the parameters for
1686 * one of the <count> binding points are invalid, that binding
1687 * point is not updated and an error will be generated. However,
1688 * other binding points in the same command will be updated if
1689 * their parameters are valid and no other error occurs."
1692 _mesa_begin_bufferobj_lookups(ctx
);
1694 for (i
= 0; i
< count
; i
++) {
1695 struct gl_buffer_object
*vbo
;
1697 /* The ARB_multi_bind spec says:
1699 * "An INVALID_VALUE error is generated if any value in
1700 * <offsets> or <strides> is negative (per binding)."
1702 if (offsets
[i
] < 0) {
1703 _mesa_error(ctx
, GL_INVALID_VALUE
,
1704 "%s(offsets[%u]=%" PRId64
" < 0)",
1705 func
, i
, (int64_t) offsets
[i
]);
1709 if (strides
[i
] < 0) {
1710 _mesa_error(ctx
, GL_INVALID_VALUE
,
1711 "%s(strides[%u]=%d < 0)",
1712 func
, i
, strides
[i
]);
1716 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1717 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
1718 _mesa_error(ctx
, GL_INVALID_VALUE
,
1719 "%s(strides[%u]=%d > "
1720 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
1725 struct gl_vertex_buffer_binding
*binding
=
1726 &vao
->VertexBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1728 if (buffers
[i
] == binding
->BufferObj
->Name
)
1729 vbo
= binding
->BufferObj
;
1731 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
1736 vbo
= ctx
->Shared
->NullBufferObj
;
1739 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1740 vbo
, offsets
[i
], strides
[i
]);
1743 _mesa_end_bufferobj_lookups(ctx
);
1748 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1749 const GLintptr
*offsets
, const GLsizei
*strides
)
1751 GET_CURRENT_CONTEXT(ctx
);
1753 /* The ARB_vertex_attrib_binding spec says:
1755 * "An INVALID_OPERATION error is generated if no
1756 * vertex array object is bound."
1758 if (ctx
->API
== API_OPENGL_CORE
&&
1759 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1760 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1761 "glBindVertexBuffers(No array object bound)");
1765 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
1766 buffers
, offsets
, strides
,
1767 "glBindVertexBuffers");
1772 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
1773 const GLuint
*buffers
,
1774 const GLintptr
*offsets
, const GLsizei
*strides
)
1776 GET_CURRENT_CONTEXT(ctx
);
1777 struct gl_vertex_array_object
*vao
;
1779 /* The ARB_direct_state_access specification says:
1781 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1782 * if <vaobj> is not [compatibility profile: zero or] the name of an
1783 * existing vertex array object."
1785 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
1789 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
1790 buffers
, offsets
, strides
,
1791 "glVertexArrayVertexBuffers");
1796 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
1797 GLboolean normalized
, GLboolean integer
,
1798 GLboolean doubles
, GLbitfield legalTypes
,
1799 GLsizei maxSize
, GLuint relativeOffset
,
1802 GET_CURRENT_CONTEXT(ctx
);
1803 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1805 /* The ARB_vertex_attrib_binding spec says:
1807 * "An INVALID_OPERATION error is generated under any of the following
1809 * - if no vertex array object is currently bound (see section 2.10);
1812 * This error condition only applies to VertexAttribFormat and
1813 * VertexAttribIFormat in the extension spec, but we assume that this
1814 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
1815 * to all three functions.
1817 if (ctx
->API
== API_OPENGL_CORE
&&
1818 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1819 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1820 "%s(No array object bound)", func
);
1824 /* The ARB_vertex_attrib_binding spec says:
1826 * "The error INVALID_VALUE is generated if index is greater than or equal
1827 * to the value of MAX_VERTEX_ATTRIBS."
1829 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1830 _mesa_error(ctx
, GL_INVALID_VALUE
,
1831 "%s(attribindex=%u > "
1832 "GL_MAX_VERTEX_ATTRIBS)",
1837 FLUSH_VERTICES(ctx
, 0);
1839 update_array_format(ctx
, func
, VERT_ATTRIB_GENERIC(attribIndex
),
1840 legalTypes
, 1, maxSize
, size
, type
, normalized
,
1841 integer
, doubles
, relativeOffset
);
1846 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1847 GLboolean normalized
, GLuint relativeOffset
)
1849 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
1850 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
1851 BGRA_OR_4
, relativeOffset
,
1852 "glVertexAttribFormat");
1857 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1858 GLuint relativeOffset
)
1860 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
1861 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
1862 relativeOffset
, "glVertexAttribIFormat");
1867 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1868 GLuint relativeOffset
)
1870 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
1871 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
1872 relativeOffset
, "glVertexAttribLFormat");
1877 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
1879 GET_CURRENT_CONTEXT(ctx
);
1880 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1882 /* The ARB_vertex_attrib_binding spec says:
1884 * "An INVALID_OPERATION error is generated if no vertex array object
1887 if (ctx
->API
== API_OPENGL_CORE
&&
1888 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1889 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1890 "glVertexAttribBinding(No array object bound)");
1894 /* The ARB_vertex_attrib_binding spec says:
1896 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1897 * <bindingindex> must be less than the value of
1898 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1901 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1902 _mesa_error(ctx
, GL_INVALID_VALUE
,
1903 "glVertexAttribBinding(attribindex=%u >= "
1904 "GL_MAX_VERTEX_ATTRIBS)",
1909 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1910 _mesa_error(ctx
, GL_INVALID_VALUE
,
1911 "glVertexAttribBinding(bindingindex=%u >= "
1912 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1917 assert(VERT_ATTRIB_GENERIC(attribIndex
) <
1918 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1920 vertex_attrib_binding(ctx
, VERT_ATTRIB_GENERIC(attribIndex
),
1921 VERT_ATTRIB_GENERIC(bindingIndex
));
1926 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
1928 GET_CURRENT_CONTEXT(ctx
);
1929 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1931 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1932 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexBindingDivisor()");
1936 /* The ARB_vertex_attrib_binding spec says:
1938 * "An INVALID_OPERATION error is generated if no vertex array object
1941 if (ctx
->API
== API_OPENGL_CORE
&&
1942 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1943 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1944 "glVertexBindingDivisor(No array object bound)");
1948 /* The ARB_vertex_attrib_binding spec says:
1950 * "An INVALID_VALUE error is generated if <bindingindex> is greater
1951 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
1953 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1954 _mesa_error(ctx
, GL_INVALID_VALUE
,
1955 "glVertexBindingDivisor(bindingindex=%u > "
1956 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1961 vertex_binding_divisor(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
1966 * Copy one client vertex array to another.
1969 _mesa_copy_client_array(struct gl_context
*ctx
,
1970 struct gl_client_array
*dst
,
1971 struct gl_client_array
*src
)
1973 dst
->Size
= src
->Size
;
1974 dst
->Type
= src
->Type
;
1975 dst
->Format
= src
->Format
;
1976 dst
->Stride
= src
->Stride
;
1977 dst
->StrideB
= src
->StrideB
;
1978 dst
->Ptr
= src
->Ptr
;
1979 dst
->Enabled
= src
->Enabled
;
1980 dst
->Normalized
= src
->Normalized
;
1981 dst
->Integer
= src
->Integer
;
1982 dst
->Doubles
= src
->Doubles
;
1983 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1984 dst
->_ElementSize
= src
->_ElementSize
;
1985 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1989 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
1990 struct gl_vertex_attrib_array
*dst
,
1991 const struct gl_vertex_attrib_array
*src
)
1993 dst
->Size
= src
->Size
;
1994 dst
->Type
= src
->Type
;
1995 dst
->Format
= src
->Format
;
1996 dst
->VertexBinding
= src
->VertexBinding
;
1997 dst
->RelativeOffset
= src
->RelativeOffset
;
1998 dst
->Format
= src
->Format
;
1999 dst
->Integer
= src
->Integer
;
2000 dst
->Doubles
= src
->Doubles
;
2001 dst
->Normalized
= src
->Normalized
;
2002 dst
->Ptr
= src
->Ptr
;
2003 dst
->Enabled
= src
->Enabled
;
2004 dst
->_ElementSize
= src
->_ElementSize
;
2008 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2009 struct gl_vertex_buffer_binding
*dst
,
2010 const struct gl_vertex_buffer_binding
*src
)
2012 dst
->Offset
= src
->Offset
;
2013 dst
->Stride
= src
->Stride
;
2014 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2015 dst
->_BoundArrays
= src
->_BoundArrays
;
2017 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2021 * Print vertex array's fields.
2024 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
2027 fprintf(stderr
, " %s[%d]: ", name
, index
);
2029 fprintf(stderr
, " %s: ", name
);
2030 fprintf(stderr
, "Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
2031 array
->Ptr
, array
->Type
, array
->Size
,
2032 array
->_ElementSize
, array
->StrideB
,
2033 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
);
2038 * Print current vertex object/array info. For debug.
2041 _mesa_print_arrays(struct gl_context
*ctx
)
2043 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2046 printf("Array Object %u\n", vao
->Name
);
2047 if (vao
->_VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
2048 print_array("Vertex", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_POS
]);
2049 if (vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
2050 print_array("Normal", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
]);
2051 if (vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
2052 print_array("Color", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
]);
2053 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
2054 if (vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
2055 print_array("TexCoord", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
2056 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
2057 if (vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
2058 print_array("Attrib", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
2063 * Initialize vertex array state for given context.
2066 _mesa_init_varray(struct gl_context
*ctx
)
2068 ctx
->Array
.DefaultVAO
= ctx
->Driver
.NewArrayObject(ctx
, 0);
2069 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2070 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2072 ctx
->Array
.Objects
= _mesa_NewHashTable();
2077 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2080 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2082 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2083 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2084 _mesa_delete_vao(ctx
, vao
);
2089 * Free vertex array state for given context.
2092 _mesa_free_varray_data(struct gl_context
*ctx
)
2094 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2095 _mesa_DeleteHashTable(ctx
->Array
.Objects
);