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)
70 /** Convert GL datatype enum into a <type>_BIT value seen above */
72 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
79 case GL_UNSIGNED_BYTE
:
80 return UNSIGNED_BYTE_BIT
;
83 case GL_UNSIGNED_SHORT
:
84 return UNSIGNED_SHORT_BIT
;
88 return UNSIGNED_INT_BIT
;
90 if (ctx
->Extensions
.ARB_half_float_vertex
)
99 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
100 case GL_UNSIGNED_INT_2_10_10_10_REV
:
101 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
102 case GL_INT_2_10_10_10_REV
:
103 return INT_2_10_10_10_REV_BIT
;
104 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
105 return UNSIGNED_INT_10F_11F_11F_REV_BIT
;
113 * Sets the VertexBinding field in the vertex attribute given by attribIndex.
116 vertex_attrib_binding(struct gl_context
*ctx
, GLuint attribIndex
,
119 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
120 struct gl_vertex_attrib_array
*array
= &vao
->VertexAttrib
[attribIndex
];
122 if (array
->VertexBinding
!= bindingIndex
) {
123 const GLbitfield64 array_bit
= VERT_BIT(attribIndex
);
125 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
127 vao
->VertexBinding
[array
->VertexBinding
]._BoundArrays
&= ~array_bit
;
128 vao
->VertexBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
130 array
->VertexBinding
= bindingIndex
;
132 vao
->NewArrays
|= array_bit
;
138 * Binds a buffer object to the vertex buffer binding point given by index,
139 * and sets the Offset and Stride fields.
142 bind_vertex_buffer(struct gl_context
*ctx
,
143 struct gl_vertex_array_object
*vao
,
145 struct gl_buffer_object
*vbo
,
146 GLintptr offset
, GLsizei stride
)
148 struct gl_vertex_buffer_binding
*binding
= &vao
->VertexBinding
[index
];
150 if (binding
->BufferObj
!= vbo
||
151 binding
->Offset
!= offset
||
152 binding
->Stride
!= stride
) {
154 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
156 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
158 binding
->Offset
= offset
;
159 binding
->Stride
= stride
;
161 vao
->NewArrays
|= binding
->_BoundArrays
;
167 * Sets the InstanceDivisor field in the vertex buffer binding point
168 * given by bindingIndex.
171 vertex_binding_divisor(struct gl_context
*ctx
, GLuint bindingIndex
,
174 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
175 struct gl_vertex_buffer_binding
*binding
=
176 &vao
->VertexBinding
[bindingIndex
];
178 if (binding
->InstanceDivisor
!= divisor
) {
179 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
180 binding
->InstanceDivisor
= divisor
;
181 vao
->NewArrays
|= binding
->_BoundArrays
;
187 * Examine the API profile and extensions to determine which types are legal
188 * for vertex arrays. This is called once from update_array_format().
191 get_legal_types_mask(const struct gl_context
*ctx
)
193 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
195 if (_mesa_is_gles(ctx
)) {
196 legalTypesMask
&= ~(FIXED_GL_BIT
|
198 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
200 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
201 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
202 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
203 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
204 * quite as trivial as we'd like because it uses a different enum value
205 * for GL_HALF_FLOAT_OES.
207 if (ctx
->Version
< 30) {
208 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
210 UNSIGNED_INT_2_10_10_10_REV_BIT
|
211 INT_2_10_10_10_REV_BIT
|
216 legalTypesMask
&= ~FIXED_ES_BIT
;
218 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
219 legalTypesMask
&= ~FIXED_GL_BIT
;
221 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
222 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
223 INT_2_10_10_10_REV_BIT
);
225 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
226 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
229 return legalTypesMask
;
234 * Does error checking and updates the format in an attrib array.
236 * Called by update_array() and VertexAttrib*Format().
238 * \param func Name of calling function used for error reporting
239 * \param attrib The index of the attribute array
240 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
241 * \param sizeMin Min allowable size value
242 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
243 * \param size Components per element (1, 2, 3 or 4)
244 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
245 * \param normalized Whether integer types are converted to floats in [-1, 1]
246 * \param integer Integer-valued values (will not be normalized to [-1, 1])
247 * \param doubles Double values not reduced to floats
248 * \param relativeOffset Offset of the first element relative to the binding offset.
251 update_array_format(struct gl_context
*ctx
,
253 GLuint attrib
, GLbitfield legalTypesMask
,
254 GLint sizeMin
, GLint sizeMax
,
255 GLint size
, GLenum type
,
256 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
257 GLuint relativeOffset
)
259 struct gl_vertex_attrib_array
*array
;
262 GLenum format
= GL_RGBA
;
264 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
265 /* Compute the LegalTypesMask only once, unless the context API has
266 * changed, in which case we want to compute it again. We can't do this
267 * in _mesa_init_varrays() below because extensions are not yet enabled
270 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
271 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
274 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
276 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
277 /* BGRA ordering is not supported in ES contexts.
282 typeBit
= type_to_bit(ctx
, type
);
283 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
284 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
285 func
, _mesa_lookup_enum_by_nr(type
));
289 /* Do size parameter checking.
290 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
291 * must be handled specially.
293 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
294 sizeMax
== BGRA_OR_4
&&
296 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
298 * "An INVALID_OPERATION error is generated under any of the following
301 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
302 * or UNSIGNED_INT_2_10_10_10_REV;
304 * • size is BGRA and normalized is FALSE;"
306 bool bgra_error
= false;
308 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
309 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
310 type
!= GL_INT_2_10_10_10_REV
&&
311 type
!= GL_UNSIGNED_BYTE
)
313 } else if (type
!= GL_UNSIGNED_BYTE
)
317 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
318 func
, _mesa_lookup_enum_by_nr(type
));
323 _mesa_error(ctx
, GL_INVALID_OPERATION
,
324 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
331 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
332 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
336 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
337 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
338 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
339 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
343 /* The ARB_vertex_attrib_binding_spec says:
345 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
346 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
348 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
349 _mesa_error(ctx
, GL_INVALID_VALUE
,
350 "%s(relativeOffset=%d > "
351 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
352 func
, relativeOffset
);
356 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
357 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
358 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
364 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
365 assert(elementSize
!= -1);
367 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
370 array
->Format
= format
;
371 array
->Normalized
= normalized
;
372 array
->Integer
= integer
;
373 array
->Doubles
= doubles
;
374 array
->RelativeOffset
= relativeOffset
;
375 array
->_ElementSize
= elementSize
;
377 ctx
->Array
.VAO
->NewArrays
|= VERT_BIT(attrib
);
378 ctx
->NewState
|= _NEW_ARRAY
;
385 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
388 * \param func name of calling function used for error reporting
389 * \param attrib the attribute array index to update
390 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
391 * \param sizeMin min allowable size value
392 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
393 * \param size components per element (1, 2, 3 or 4)
394 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
395 * \param stride stride between elements, in elements
396 * \param normalized are integer types converted to floats in [-1, 1]?
397 * \param integer integer-valued values (will not be normalized to [-1,1])
398 * \param doubles Double values not reduced to floats
399 * \param ptr the address (or offset inside VBO) of the array data
402 update_array(struct gl_context
*ctx
,
404 GLuint attrib
, GLbitfield legalTypesMask
,
405 GLint sizeMin
, GLint sizeMax
,
406 GLint size
, GLenum type
, GLsizei stride
,
407 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
410 struct gl_vertex_attrib_array
*array
;
411 GLsizei effectiveStride
;
413 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
415 * "Client vertex arrays - all vertex array attribute pointers must
416 * refer to buffer objects (section 2.9.2). The default vertex array
417 * object (the name zero) is also deprecated. Calling
418 * VertexAttribPointer when no buffer object or no vertex array object
419 * is bound will generate an INVALID_OPERATION error..."
421 * The check for VBOs is handled below.
423 if (ctx
->API
== API_OPENGL_CORE
424 && (ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
)) {
425 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
431 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
435 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
436 stride
> ctx
->Const
.MaxVertexAttribStride
) {
437 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
438 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
442 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
444 * "An INVALID_OPERATION error is generated under any of the following
449 * * any of the *Pointer commands specifying the location and
450 * organization of vertex array data are called while zero is bound
451 * to the ARRAY_BUFFER buffer object binding point (see section
452 * 2.9.6), and the pointer argument is not NULL."
454 if (ptr
!= NULL
&& ctx
->Array
.VAO
->ARBsemantics
&&
455 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
456 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
460 if (!update_array_format(ctx
, func
, attrib
, legalTypesMask
, sizeMin
,
461 sizeMax
, size
, type
, normalized
, integer
, doubles
, 0)) {
465 /* Reset the vertex attrib binding */
466 vertex_attrib_binding(ctx
, attrib
, attrib
);
468 /* The Stride and Ptr fields are not set by update_array_format() */
469 array
= &ctx
->Array
.VAO
->VertexAttrib
[attrib
];
470 array
->Stride
= stride
;
471 array
->Ptr
= (const GLvoid
*) ptr
;
473 /* Update the vertex buffer binding */
474 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
475 bind_vertex_buffer(ctx
, ctx
->Array
.VAO
, attrib
, ctx
->Array
.ArrayBufferObj
,
476 (GLintptr
) ptr
, effectiveStride
);
481 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
483 GET_CURRENT_CONTEXT(ctx
);
484 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
485 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
486 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
487 DOUBLE_BIT
| HALF_BIT
|
488 UNSIGNED_INT_2_10_10_10_REV_BIT
|
489 INT_2_10_10_10_REV_BIT
);
491 FLUSH_VERTICES(ctx
, 0);
493 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
495 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
500 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
502 GET_CURRENT_CONTEXT(ctx
);
503 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
504 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
505 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
506 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
507 UNSIGNED_INT_2_10_10_10_REV_BIT
|
508 INT_2_10_10_10_REV_BIT
);
510 FLUSH_VERTICES(ctx
, 0);
512 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
514 3, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
519 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
521 GET_CURRENT_CONTEXT(ctx
);
522 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
523 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
524 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
525 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
526 INT_BIT
| UNSIGNED_INT_BIT
|
527 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
528 UNSIGNED_INT_2_10_10_10_REV_BIT
|
529 INT_2_10_10_10_REV_BIT
);
530 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
532 FLUSH_VERTICES(ctx
, 0);
534 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
535 legalTypes
, sizeMin
, BGRA_OR_4
,
536 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
541 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
543 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
544 GET_CURRENT_CONTEXT(ctx
);
546 FLUSH_VERTICES(ctx
, 0);
548 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
550 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
555 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
557 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
558 FLOAT_BIT
| DOUBLE_BIT
);
559 GET_CURRENT_CONTEXT(ctx
);
561 FLUSH_VERTICES(ctx
, 0);
563 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
565 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
570 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
571 GLsizei stride
, const GLvoid
*ptr
)
573 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
574 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
575 INT_BIT
| UNSIGNED_INT_BIT
|
576 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
577 UNSIGNED_INT_2_10_10_10_REV_BIT
|
578 INT_2_10_10_10_REV_BIT
);
579 GET_CURRENT_CONTEXT(ctx
);
581 FLUSH_VERTICES(ctx
, 0);
583 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
584 legalTypes
, 3, BGRA_OR_4
,
585 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
590 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
593 GET_CURRENT_CONTEXT(ctx
);
594 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
595 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
596 : (SHORT_BIT
| INT_BIT
|
597 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
598 UNSIGNED_INT_2_10_10_10_REV_BIT
|
599 INT_2_10_10_10_REV_BIT
);
600 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
601 const GLuint unit
= ctx
->Array
.ActiveTexture
;
603 FLUSH_VERTICES(ctx
, 0);
605 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
606 legalTypes
, sizeMin
, 4,
607 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
613 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
615 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
616 /* this is the same type that glEdgeFlag uses */
617 const GLboolean integer
= GL_FALSE
;
618 GET_CURRENT_CONTEXT(ctx
);
620 FLUSH_VERTICES(ctx
, 0);
622 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
624 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
629 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
631 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
632 GET_CURRENT_CONTEXT(ctx
);
634 FLUSH_VERTICES(ctx
, 0);
636 if (ctx
->API
!= API_OPENGLES
) {
637 _mesa_error(ctx
, GL_INVALID_OPERATION
,
638 "glPointSizePointer(ES 1.x only)");
642 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
644 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
649 * Set a generic vertex attribute array.
650 * Note that these arrays DO NOT alias the conventional GL vertex arrays
651 * (position, normal, color, fog, texcoord, etc).
654 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
655 GLboolean normalized
,
656 GLsizei stride
, const GLvoid
*ptr
)
658 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
659 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
660 INT_BIT
| UNSIGNED_INT_BIT
|
661 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
662 FIXED_ES_BIT
| FIXED_GL_BIT
|
663 UNSIGNED_INT_2_10_10_10_REV_BIT
|
664 INT_2_10_10_10_REV_BIT
|
665 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
666 GET_CURRENT_CONTEXT(ctx
);
668 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
669 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
673 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
674 legalTypes
, 1, BGRA_OR_4
,
675 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
680 * GL_EXT_gpu_shader4 / GL 3.0.
681 * Set an integer-valued vertex attribute array.
682 * Note that these arrays DO NOT alias the conventional GL vertex arrays
683 * (position, normal, color, fog, texcoord, etc).
686 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
687 GLsizei stride
, const GLvoid
*ptr
)
689 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
690 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
691 INT_BIT
| UNSIGNED_INT_BIT
);
692 const GLboolean normalized
= GL_FALSE
;
693 const GLboolean integer
= GL_TRUE
;
694 GET_CURRENT_CONTEXT(ctx
);
696 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
697 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
701 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
703 size
, type
, stride
, normalized
, integer
, GL_FALSE
, ptr
);
707 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
708 GLsizei stride
, const GLvoid
*ptr
)
710 GET_CURRENT_CONTEXT(ctx
);
711 const GLbitfield legalTypes
= (DOUBLE_BIT
);
712 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
713 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
717 update_array(ctx
, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index
),
719 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_TRUE
, ptr
);
724 enable_vertex_array_attrib(struct gl_context
*ctx
,
725 struct gl_vertex_array_object
*vao
,
729 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
730 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
734 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
736 if (!vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
737 /* was disabled, now being enabled */
738 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
739 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
740 vao
->_Enabled
|= VERT_BIT_GENERIC(index
);
741 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
747 _mesa_EnableVertexAttribArray(GLuint index
)
749 GET_CURRENT_CONTEXT(ctx
);
750 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
751 "glEnableVertexAttribArray");
756 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
758 GET_CURRENT_CONTEXT(ctx
);
759 struct gl_vertex_array_object
*vao
;
761 /* The ARB_direct_state_access specification says:
763 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
764 * and DisableVertexArrayAttrib if <vaobj> is not
765 * [compatibility profile: zero or] the name of an existing vertex
768 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
772 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
777 disable_vertex_array_attrib(struct gl_context
*ctx
,
778 struct gl_vertex_array_object
*vao
,
782 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
783 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
787 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
789 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
790 /* was enabled, now being disabled */
791 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
792 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
793 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
794 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
800 _mesa_DisableVertexAttribArray(GLuint index
)
802 GET_CURRENT_CONTEXT(ctx
);
803 disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
804 "glDisableVertexAttribArray");
809 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
811 GET_CURRENT_CONTEXT(ctx
);
812 struct gl_vertex_array_object
*vao
;
814 /* The ARB_direct_state_access specification says:
816 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
817 * and DisableVertexArrayAttrib if <vaobj> is not
818 * [compatibility profile: zero or] the name of an existing vertex
821 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
825 disable_vertex_array_attrib(ctx
, vao
, index
, "glDisableVertexArrayAttrib");
830 * Return info for a vertex attribute array (no alias with legacy
831 * vertex attributes (pos, normal, color, etc)). This function does
832 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
835 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
838 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
839 const struct gl_vertex_attrib_array
*array
;
841 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
842 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
846 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
848 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
851 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
852 return array
->Enabled
;
853 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
854 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
855 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
856 return array
->Stride
;
857 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
859 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
860 return array
->Normalized
;
861 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
862 return vao
->VertexBinding
[array
->VertexBinding
].BufferObj
->Name
;
863 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
864 if ((_mesa_is_desktop_gl(ctx
)
865 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
866 || _mesa_is_gles3(ctx
)) {
867 return array
->Integer
;
870 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
871 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
872 || _mesa_is_gles3(ctx
)) {
873 return vao
->VertexBinding
[array
->VertexBinding
].InstanceDivisor
;
876 case GL_VERTEX_ATTRIB_BINDING
:
877 if (_mesa_is_desktop_gl(ctx
)) {
878 return array
->VertexBinding
- VERT_ATTRIB_GENERIC0
;
881 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
882 if (_mesa_is_desktop_gl(ctx
)) {
883 return array
->RelativeOffset
;
891 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
896 static const GLfloat
*
897 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
900 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
901 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
905 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
906 _mesa_error(ctx
, GL_INVALID_VALUE
,
907 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
911 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
913 FLUSH_CURRENT(ctx
, 0);
914 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
918 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
920 GET_CURRENT_CONTEXT(ctx
);
922 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
923 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
929 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
930 "glGetVertexAttribfv");
936 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
938 GET_CURRENT_CONTEXT(ctx
);
940 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
941 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
943 params
[0] = (GLdouble
) v
[0];
944 params
[1] = (GLdouble
) v
[1];
945 params
[2] = (GLdouble
) v
[2];
946 params
[3] = (GLdouble
) v
[3];
950 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
951 "glGetVertexAttribdv");
956 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
958 GET_CURRENT_CONTEXT(ctx
);
960 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
961 const GLdouble
*v
= (const GLdouble
*)get_current_attrib(ctx
, index
, "glGetVertexAttribLdv");
970 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
971 "glGetVertexAttribLdv");
976 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
978 GET_CURRENT_CONTEXT(ctx
);
980 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
981 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
983 /* XXX should floats in[0,1] be scaled to full int range? */
984 params
[0] = (GLint
) v
[0];
985 params
[1] = (GLint
) v
[1];
986 params
[2] = (GLint
) v
[2];
987 params
[3] = (GLint
) v
[3];
991 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
992 "glGetVertexAttribiv");
999 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1001 GET_CURRENT_CONTEXT(ctx
);
1003 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1004 const GLint
*v
= (const GLint
*)
1005 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1011 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
1012 "glGetVertexAttribIiv");
1019 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1021 GET_CURRENT_CONTEXT(ctx
);
1023 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1024 const GLuint
*v
= (const GLuint
*)
1025 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1031 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
1032 "glGetVertexAttribIuiv");
1038 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1040 GET_CURRENT_CONTEXT(ctx
);
1042 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1043 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1047 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1048 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1052 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1054 *pointer
= (GLvoid
*) ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1059 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1060 GLsizei count
, const GLvoid
*ptr
)
1063 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1068 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1072 _mesa_NormalPointer(type
, stride
, ptr
);
1077 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1081 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1086 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1090 _mesa_IndexPointer(type
, stride
, ptr
);
1095 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1096 GLsizei count
, const GLvoid
*ptr
)
1099 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1104 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1107 _mesa_EdgeFlagPointer(stride
, ptr
);
1112 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1114 GET_CURRENT_CONTEXT(ctx
);
1115 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1116 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1117 GLenum ctype
= 0; /* color type */
1118 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1119 const GLint toffset
= 0; /* always zero */
1120 GLint defstride
; /* default stride */
1123 FLUSH_VERTICES(ctx
, 0);
1125 f
= sizeof(GLfloat
);
1126 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1129 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1135 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1136 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1141 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1142 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1147 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1148 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1149 ctype
= GL_UNSIGNED_BYTE
;
1152 defstride
= c
+ 2*f
;
1155 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1156 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1157 ctype
= GL_UNSIGNED_BYTE
;
1160 defstride
= c
+ 3*f
;
1163 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1164 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1171 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1172 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1177 case GL_C4F_N3F_V3F
:
1178 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1179 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1187 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1188 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1193 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1194 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1198 case GL_T2F_C4UB_V3F
:
1199 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1200 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1201 ctype
= GL_UNSIGNED_BYTE
;
1206 case GL_T2F_C3F_V3F
:
1207 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1208 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1214 case GL_T2F_N3F_V3F
:
1215 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1216 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1221 case GL_T2F_C4F_N3F_V3F
:
1222 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1223 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1230 case GL_T4F_C4F_N3F_V4F
:
1231 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1232 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1240 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1248 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1249 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1250 /* XXX also disable secondary color and generic arrays? */
1254 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1255 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1256 (GLubyte
*) pointer
+ toffset
);
1259 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1264 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1265 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1266 (GLubyte
*) pointer
+ coffset
);
1269 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1275 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1276 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1279 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1283 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1284 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1285 (GLubyte
*) pointer
+ voffset
);
1290 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1292 GET_CURRENT_CONTEXT(ctx
);
1294 FLUSH_VERTICES(ctx
, 0);
1296 if (MESA_VERBOSE
& VERBOSE_API
)
1297 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1300 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1304 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1307 if (ctx
->Array
.LockCount
!= 0) {
1308 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1312 ctx
->Array
.LockFirst
= first
;
1313 ctx
->Array
.LockCount
= count
;
1315 ctx
->NewState
|= _NEW_ARRAY
;
1320 _mesa_UnlockArraysEXT( void )
1322 GET_CURRENT_CONTEXT(ctx
);
1324 FLUSH_VERTICES(ctx
, 0);
1326 if (MESA_VERBOSE
& VERBOSE_API
)
1327 _mesa_debug(ctx
, "glUnlockArrays\n");
1329 if (ctx
->Array
.LockCount
== 0) {
1330 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1334 ctx
->Array
.LockFirst
= 0;
1335 ctx
->Array
.LockCount
= 0;
1336 ctx
->NewState
|= _NEW_ARRAY
;
1340 /* GL_EXT_multi_draw_arrays */
1342 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1343 const GLsizei
*count
, GLsizei primcount
)
1345 GET_CURRENT_CONTEXT(ctx
);
1348 FLUSH_VERTICES(ctx
, 0);
1350 for (i
= 0; i
< primcount
; i
++) {
1352 CALL_DrawArrays(ctx
->CurrentDispatch
, (mode
, first
[i
], count
[i
]));
1358 /* GL_IBM_multimode_draw_arrays */
1360 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1361 const GLsizei
* count
,
1362 GLsizei primcount
, GLint modestride
)
1364 GET_CURRENT_CONTEXT(ctx
);
1367 FLUSH_VERTICES(ctx
, 0);
1369 for ( i
= 0 ; i
< primcount
; i
++ ) {
1370 if ( count
[i
] > 0 ) {
1371 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1372 CALL_DrawArrays(ctx
->CurrentDispatch
, ( m
, first
[i
], count
[i
] ));
1378 /* GL_IBM_multimode_draw_arrays */
1380 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1381 GLenum type
, const GLvoid
* const * indices
,
1382 GLsizei primcount
, GLint modestride
)
1384 GET_CURRENT_CONTEXT(ctx
);
1387 FLUSH_VERTICES(ctx
, 0);
1389 /* XXX not sure about ARB_vertex_buffer_object handling here */
1391 for ( i
= 0 ; i
< primcount
; i
++ ) {
1392 if ( count
[i
] > 0 ) {
1393 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1394 CALL_DrawElements(ctx
->CurrentDispatch
, ( m
, count
[i
], type
,
1402 * GL_NV_primitive_restart and GL 3.1
1405 _mesa_PrimitiveRestartIndex(GLuint index
)
1407 GET_CURRENT_CONTEXT(ctx
);
1409 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1410 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1414 if (ctx
->Array
.RestartIndex
!= index
) {
1415 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1416 ctx
->Array
.RestartIndex
= index
;
1422 * See GL_ARB_instanced_arrays.
1423 * Note that the instance divisor only applies to generic arrays, not
1424 * the legacy vertex arrays.
1427 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1429 GET_CURRENT_CONTEXT(ctx
);
1431 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1433 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1434 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1438 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1439 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1444 assert(genericIndex
< ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1446 /* The ARB_vertex_attrib_binding spec says:
1450 * void VertexAttribDivisor(uint index, uint divisor);
1452 * is equivalent to (assuming no errors are generated):
1454 * VertexAttribBinding(index, index);
1455 * VertexBindingDivisor(index, divisor);"
1457 vertex_attrib_binding(ctx
, genericIndex
, genericIndex
);
1458 vertex_binding_divisor(ctx
, genericIndex
, divisor
);
1463 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1465 /* From the OpenGL 4.3 core specification, page 302:
1466 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1467 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1470 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1472 case GL_UNSIGNED_BYTE
:
1474 case GL_UNSIGNED_SHORT
:
1476 case GL_UNSIGNED_INT
:
1479 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1483 return ctx
->Array
.RestartIndex
;
1488 * GL_ARB_vertex_attrib_binding
1491 vertex_array_vertex_buffer(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
,
1492 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1493 GLsizei stride
, const char *func
)
1495 struct gl_buffer_object
*vbo
;
1497 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1499 /* The ARB_vertex_attrib_binding spec says:
1501 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1502 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1504 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1505 _mesa_error(ctx
, GL_INVALID_VALUE
,
1506 "%s(bindingindex=%u > "
1507 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1508 func
, bindingIndex
);
1512 /* The ARB_vertex_attrib_binding spec says:
1514 * "The error INVALID_VALUE is generated if <stride> or <offset>
1518 _mesa_error(ctx
, GL_INVALID_VALUE
,
1519 "%s(offset=%" PRId64
" < 0)",
1520 func
, (int64_t) offset
);
1525 _mesa_error(ctx
, GL_INVALID_VALUE
,
1526 "%s(stride=%d < 0)", func
, stride
);
1530 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1531 stride
> ctx
->Const
.MaxVertexAttribStride
) {
1532 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
1533 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
1537 if (buffer
== vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1538 vbo
= vao
->VertexBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1539 } else if (buffer
!= 0) {
1540 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1542 /* From the GL_ARB_vertex_attrib_array spec:
1544 * "[Core profile only:]
1545 * An INVALID_OPERATION error is generated if buffer is not zero or a
1546 * name returned from a previous call to GenBuffers, or if such a name
1547 * has since been deleted with DeleteBuffers.
1549 * Otherwise, we fall back to the same compat profile behavior as other
1550 * object references (automatically gen it).
1552 if (!_mesa_handle_bind_buffer_gen(ctx
, GL_ARRAY_BUFFER
, buffer
,
1556 /* The ARB_vertex_attrib_binding spec says:
1558 * "If <buffer> is zero, any buffer object attached to this
1559 * bindpoint is detached."
1561 vbo
= ctx
->Shared
->NullBufferObj
;
1564 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
1565 vbo
, offset
, stride
);
1570 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1573 GET_CURRENT_CONTEXT(ctx
);
1575 /* The ARB_vertex_attrib_binding spec says:
1577 * "An INVALID_OPERATION error is generated if no vertex array object
1580 if (ctx
->API
== API_OPENGL_CORE
&&
1581 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1582 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1583 "glBindVertexBuffer(No array object bound)");
1587 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
1588 buffer
, offset
, stride
, "glBindVertexBuffer");
1593 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
1594 GLintptr offset
, GLsizei stride
)
1596 GET_CURRENT_CONTEXT(ctx
);
1597 struct gl_vertex_array_object
*vao
;
1599 /* The ARB_direct_state_access specification says:
1601 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1602 * if <vaobj> is not [compatibility profile: zero or] the name of an
1603 * existing vertex array object."
1605 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
1609 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
,
1610 buffer
, offset
, stride
,
1611 "glVertexArrayVertexBuffer");
1616 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1617 const GLintptr
*offsets
, const GLsizei
*strides
)
1619 GET_CURRENT_CONTEXT(ctx
);
1620 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1623 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1625 /* The ARB_vertex_attrib_binding spec says:
1627 * "An INVALID_OPERATION error is generated if no
1628 * vertex array object is bound."
1630 if (ctx
->API
== API_OPENGL_CORE
&&
1631 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1632 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1633 "glBindVertexBuffers(No array object bound)");
1637 /* The ARB_multi_bind spec says:
1639 * "An INVALID_OPERATION error is generated if <first> + <count>
1640 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1642 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1643 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1644 "glBindVertexBuffers(first=%u + count=%d > the value of "
1645 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1646 first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1652 * The ARB_multi_bind spec says:
1654 * "If <buffers> is NULL, each affected vertex buffer binding point
1655 * from <first> through <first>+<count>-1 will be reset to have no
1656 * bound buffer object. In this case, the offsets and strides
1657 * associated with the binding points are set to default values,
1658 * ignoring <offsets> and <strides>."
1660 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1662 for (i
= 0; i
< count
; i
++)
1663 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1669 /* Note that the error semantics for multi-bind commands differ from
1670 * those of other GL commands.
1672 * The Issues section in the ARB_multi_bind spec says:
1674 * "(11) Typically, OpenGL specifies that if an error is generated by
1675 * a command, that command has no effect. This is somewhat
1676 * unfortunate for multi-bind commands, because it would require
1677 * a first pass to scan the entire list of bound objects for
1678 * errors and then a second pass to actually perform the
1679 * bindings. Should we have different error semantics?
1681 * RESOLVED: Yes. In this specification, when the parameters for
1682 * one of the <count> binding points are invalid, that binding
1683 * point is not updated and an error will be generated. However,
1684 * other binding points in the same command will be updated if
1685 * their parameters are valid and no other error occurs."
1688 _mesa_begin_bufferobj_lookups(ctx
);
1690 for (i
= 0; i
< count
; i
++) {
1691 struct gl_buffer_object
*vbo
;
1693 /* The ARB_multi_bind spec says:
1695 * "An INVALID_VALUE error is generated if any value in
1696 * <offsets> or <strides> is negative (per binding)."
1698 if (offsets
[i
] < 0) {
1699 _mesa_error(ctx
, GL_INVALID_VALUE
,
1700 "glBindVertexBuffers(offsets[%u]=%" PRId64
" < 0)",
1701 i
, (int64_t) offsets
[i
]);
1705 if (strides
[i
] < 0) {
1706 _mesa_error(ctx
, GL_INVALID_VALUE
,
1707 "glBindVertexBuffers(strides[%u]=%d < 0)",
1712 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1713 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
1714 _mesa_error(ctx
, GL_INVALID_VALUE
,
1715 "glBindVertexBuffers(strides[%u]=%d > "
1716 "GL_MAX_VERTEX_ATTRIB_STRIDE)", i
, strides
[i
]);
1721 struct gl_vertex_buffer_binding
*binding
=
1722 &vao
->VertexBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1724 if (buffers
[i
] == binding
->BufferObj
->Name
)
1725 vbo
= binding
->BufferObj
;
1727 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
,
1728 "glBindVertexBuffers");
1733 vbo
= ctx
->Shared
->NullBufferObj
;
1736 bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1737 vbo
, offsets
[i
], strides
[i
]);
1740 _mesa_end_bufferobj_lookups(ctx
);
1745 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1746 GLboolean normalized
, GLuint relativeOffset
)
1748 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1749 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1750 INT_BIT
| UNSIGNED_INT_BIT
|
1751 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1753 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1754 INT_2_10_10_10_REV_BIT
|
1755 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1757 GET_CURRENT_CONTEXT(ctx
);
1758 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1760 /* The ARB_vertex_attrib_binding spec says:
1762 * "An INVALID_OPERATION error is generated under any of the following
1764 * - if no vertex array object is currently bound (see section 2.10);
1767 if (ctx
->API
== API_OPENGL_CORE
&&
1768 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1769 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1770 "glVertexAttribFormat(No array object bound)");
1774 /* The ARB_vertex_attrib_binding spec says:
1776 * "The error INVALID_VALUE is generated if index is greater than or equal
1777 * to the value of MAX_VERTEX_ATTRIBS."
1779 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1780 _mesa_error(ctx
, GL_INVALID_VALUE
,
1781 "glVertexAttribFormat(attribindex=%u > "
1782 "GL_MAX_VERTEX_ATTRIBS)",
1787 FLUSH_VERTICES(ctx
, 0);
1789 update_array_format(ctx
, "glVertexAttribFormat",
1790 VERT_ATTRIB_GENERIC(attribIndex
),
1791 legalTypes
, 1, BGRA_OR_4
, size
, type
, normalized
,
1792 GL_FALSE
, GL_FALSE
, relativeOffset
);
1797 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1798 GLuint relativeOffset
)
1800 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1801 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1802 INT_BIT
| UNSIGNED_INT_BIT
);
1804 GET_CURRENT_CONTEXT(ctx
);
1805 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1807 /* The ARB_vertex_attrib_binding spec says:
1809 * "An INVALID_OPERATION error is generated under any of the following
1811 * - if no vertex array object is currently bound (see section 2.10);
1814 if (ctx
->API
== API_OPENGL_CORE
&&
1815 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1816 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1817 "glVertexAttribIFormat(No array object bound)");
1821 /* The ARB_vertex_attrib_binding spec says:
1823 * "The error INVALID_VALUE is generated if index is greater than
1824 * or equal to the value of MAX_VERTEX_ATTRIBS."
1826 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1827 _mesa_error(ctx
, GL_INVALID_VALUE
,
1828 "glVertexAttribIFormat(attribindex=%u > "
1829 "GL_MAX_VERTEX_ATTRIBS)",
1834 FLUSH_VERTICES(ctx
, 0);
1836 update_array_format(ctx
, "glVertexAttribIFormat",
1837 VERT_ATTRIB_GENERIC(attribIndex
),
1838 legalTypes
, 1, 4, size
, type
, GL_FALSE
, GL_TRUE
, GL_FALSE
,
1844 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1845 GLuint relativeOffset
)
1847 const GLbitfield legalTypes
= DOUBLE_BIT
;
1849 GET_CURRENT_CONTEXT(ctx
);
1850 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1852 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
1854 * "An INVALID_OPERATION error is generated under any of the following
1856 * • if no vertex array object is currently bound (see section 10.4);
1859 * This language is missing from the extension spec, but we assume
1860 * that this is an oversight.
1862 if (ctx
->API
== API_OPENGL_CORE
&&
1863 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1864 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1865 "glVertexAttribLFormat(No array object bound)");
1869 /* The ARB_vertex_attrib_binding spec says:
1871 * "The error INVALID_VALUE is generated if <attribindex> is greater than
1872 * or equal to the value of MAX_VERTEX_ATTRIBS."
1874 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1875 _mesa_error(ctx
, GL_INVALID_VALUE
,
1876 "glVertexAttribLFormat(attribindex=%u > "
1877 "GL_MAX_VERTEX_ATTRIBS)",
1882 FLUSH_VERTICES(ctx
, 0);
1884 update_array_format(ctx
, "glVertexAttribLFormat",
1885 VERT_ATTRIB_GENERIC(attribIndex
),
1886 legalTypes
, 1, 4, size
, type
, GL_FALSE
, GL_FALSE
, GL_TRUE
,
1892 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
1894 GET_CURRENT_CONTEXT(ctx
);
1895 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1897 /* The ARB_vertex_attrib_binding spec says:
1899 * "An INVALID_OPERATION error is generated if no vertex array object
1902 if (ctx
->API
== API_OPENGL_CORE
&&
1903 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1904 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1905 "glVertexAttribBinding(No array object bound)");
1909 /* The ARB_vertex_attrib_binding spec says:
1911 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1912 * <bindingindex> must be less than the value of
1913 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1916 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1917 _mesa_error(ctx
, GL_INVALID_VALUE
,
1918 "glVertexAttribBinding(attribindex=%u >= "
1919 "GL_MAX_VERTEX_ATTRIBS)",
1924 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1925 _mesa_error(ctx
, GL_INVALID_VALUE
,
1926 "glVertexAttribBinding(bindingindex=%u >= "
1927 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1932 assert(VERT_ATTRIB_GENERIC(attribIndex
) <
1933 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1935 vertex_attrib_binding(ctx
, VERT_ATTRIB_GENERIC(attribIndex
),
1936 VERT_ATTRIB_GENERIC(bindingIndex
));
1941 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
1943 GET_CURRENT_CONTEXT(ctx
);
1944 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1946 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1947 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexBindingDivisor()");
1951 /* The ARB_vertex_attrib_binding spec says:
1953 * "An INVALID_OPERATION error is generated if no vertex array object
1956 if (ctx
->API
== API_OPENGL_CORE
&&
1957 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1958 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1959 "glVertexBindingDivisor(No array object bound)");
1963 /* The ARB_vertex_attrib_binding spec says:
1965 * "An INVALID_VALUE error is generated if <bindingindex> is greater
1966 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
1968 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1969 _mesa_error(ctx
, GL_INVALID_VALUE
,
1970 "glVertexBindingDivisor(bindingindex=%u > "
1971 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1976 vertex_binding_divisor(ctx
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
1981 * Copy one client vertex array to another.
1984 _mesa_copy_client_array(struct gl_context
*ctx
,
1985 struct gl_client_array
*dst
,
1986 struct gl_client_array
*src
)
1988 dst
->Size
= src
->Size
;
1989 dst
->Type
= src
->Type
;
1990 dst
->Format
= src
->Format
;
1991 dst
->Stride
= src
->Stride
;
1992 dst
->StrideB
= src
->StrideB
;
1993 dst
->Ptr
= src
->Ptr
;
1994 dst
->Enabled
= src
->Enabled
;
1995 dst
->Normalized
= src
->Normalized
;
1996 dst
->Integer
= src
->Integer
;
1997 dst
->Doubles
= src
->Doubles
;
1998 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1999 dst
->_ElementSize
= src
->_ElementSize
;
2000 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2004 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2005 struct gl_vertex_attrib_array
*dst
,
2006 const struct gl_vertex_attrib_array
*src
)
2008 dst
->Size
= src
->Size
;
2009 dst
->Type
= src
->Type
;
2010 dst
->Format
= src
->Format
;
2011 dst
->VertexBinding
= src
->VertexBinding
;
2012 dst
->RelativeOffset
= src
->RelativeOffset
;
2013 dst
->Format
= src
->Format
;
2014 dst
->Integer
= src
->Integer
;
2015 dst
->Doubles
= src
->Doubles
;
2016 dst
->Normalized
= src
->Normalized
;
2017 dst
->Ptr
= src
->Ptr
;
2018 dst
->Enabled
= src
->Enabled
;
2019 dst
->_ElementSize
= src
->_ElementSize
;
2023 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2024 struct gl_vertex_buffer_binding
*dst
,
2025 const struct gl_vertex_buffer_binding
*src
)
2027 dst
->Offset
= src
->Offset
;
2028 dst
->Stride
= src
->Stride
;
2029 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2030 dst
->_BoundArrays
= src
->_BoundArrays
;
2032 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2036 * Print vertex array's fields.
2039 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
2042 fprintf(stderr
, " %s[%d]: ", name
, index
);
2044 fprintf(stderr
, " %s: ", name
);
2045 fprintf(stderr
, "Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
2046 array
->Ptr
, array
->Type
, array
->Size
,
2047 array
->_ElementSize
, array
->StrideB
,
2048 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
);
2053 * Print current vertex object/array info. For debug.
2056 _mesa_print_arrays(struct gl_context
*ctx
)
2058 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2061 printf("Array Object %u\n", vao
->Name
);
2062 if (vao
->_VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
2063 print_array("Vertex", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_POS
]);
2064 if (vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
2065 print_array("Normal", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_NORMAL
]);
2066 if (vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
2067 print_array("Color", -1, &vao
->_VertexAttrib
[VERT_ATTRIB_COLOR0
]);
2068 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
2069 if (vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
2070 print_array("TexCoord", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
2071 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
2072 if (vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
2073 print_array("Attrib", i
, &vao
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
2078 * Initialize vertex array state for given context.
2081 _mesa_init_varray(struct gl_context
*ctx
)
2083 ctx
->Array
.DefaultVAO
= ctx
->Driver
.NewArrayObject(ctx
, 0);
2084 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2085 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2087 ctx
->Array
.Objects
= _mesa_NewHashTable();
2092 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2095 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2097 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2098 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2099 _mesa_delete_vao(ctx
, vao
);
2104 * Free vertex array state for given context.
2107 _mesa_free_varray_data(struct gl_context
*ctx
)
2109 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2110 _mesa_DeleteHashTable(ctx
->Array
.Objects
);