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.
29 #include "bufferobj.h"
39 #include "main/dispatch.h"
42 /** Used to do error checking for GL_EXT_vertex_array_bgra */
46 /** Used to indicate which GL datatypes are accepted by each of the
47 * glVertex/Color/Attrib/EtcPointer() functions.
51 #define UNSIGNED_BYTE_BIT 0x4
53 #define UNSIGNED_SHORT_BIT 0x10
55 #define UNSIGNED_INT_BIT 0x40
57 #define FLOAT_BIT 0x100
58 #define DOUBLE_BIT 0x200
59 #define FIXED_ES_BIT 0x400
60 #define FIXED_GL_BIT 0x800
61 #define UNSIGNED_INT_2_10_10_10_REV_BIT 0x1000
62 #define INT_2_10_10_10_REV_BIT 0x2000
65 /** Convert GL datatype enum into a <type>_BIT value seen above */
67 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
74 case GL_UNSIGNED_BYTE
:
75 return UNSIGNED_BYTE_BIT
;
78 case GL_UNSIGNED_SHORT
:
79 return UNSIGNED_SHORT_BIT
;
83 return UNSIGNED_INT_BIT
;
85 if (ctx
->Extensions
.ARB_half_float_vertex
)
94 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
95 case GL_UNSIGNED_INT_2_10_10_10_REV
:
96 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
97 case GL_INT_2_10_10_10_REV
:
98 return INT_2_10_10_10_REV_BIT
;
106 * Does error checking and updates the format in an attrib array.
108 * Called by update_array().
110 * \param func Name of calling function used for error reporting
111 * \param attrib The index of the attribute array
112 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
113 * \param sizeMin Min allowable size value
114 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
115 * \param size Components per element (1, 2, 3 or 4)
116 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
117 * \param normalized Whether integer types are converted to floats in [-1, 1]
118 * \param integer Integer-valued values (will not be normalized to [-1, 1])
121 update_array_format(struct gl_context
*ctx
,
123 GLuint attrib
, GLbitfield legalTypesMask
,
124 GLint sizeMin
, GLint sizeMax
,
125 GLint size
, GLenum type
,
126 GLboolean normalized
, GLboolean integer
)
128 struct gl_client_array
*array
;
131 GLenum format
= GL_RGBA
;
133 if (_mesa_is_gles(ctx
)) {
134 legalTypesMask
&= ~(FIXED_GL_BIT
| DOUBLE_BIT
);
136 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
137 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
138 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
139 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
140 * quite as trivial as we'd like because it uses a different enum value
141 * for GL_HALF_FLOAT_OES.
143 if (ctx
->Version
< 30) {
144 legalTypesMask
&= ~(UNSIGNED_INT_BIT
146 | UNSIGNED_INT_2_10_10_10_REV_BIT
147 | INT_2_10_10_10_REV_BIT
151 /* BGRA ordering is not supported in ES contexts.
153 if (sizeMax
== BGRA_OR_4
)
156 legalTypesMask
&= ~FIXED_ES_BIT
;
158 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
159 legalTypesMask
&= ~FIXED_GL_BIT
;
161 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
162 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
163 INT_2_10_10_10_REV_BIT
);
166 typeBit
= type_to_bit(ctx
, type
);
167 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
168 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
169 func
, _mesa_lookup_enum_by_nr(type
));
173 /* Do size parameter checking.
174 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
175 * must be handled specially.
177 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
178 sizeMax
== BGRA_OR_4
&&
180 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
182 * "An INVALID_OPERATION error is generated under any of the following
185 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
186 * or UNSIGNED_INT_2_10_10_10_REV;
188 * • size is BGRA and normalized is FALSE;"
190 bool bgra_error
= false;
192 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
193 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
194 type
!= GL_INT_2_10_10_10_REV
&&
195 type
!= GL_UNSIGNED_BYTE
)
197 } else if (type
!= GL_UNSIGNED_BYTE
)
201 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
202 func
, _mesa_lookup_enum_by_nr(type
));
207 _mesa_error(ctx
, GL_INVALID_OPERATION
,
208 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
215 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
216 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
220 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
221 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
222 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
223 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
229 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
230 assert(elementSize
!= -1);
232 array
= &ctx
->Array
.ArrayObj
->_VertexAttrib
[attrib
];
235 array
->Format
= format
;
236 array
->Normalized
= normalized
;
237 array
->Integer
= integer
;
238 array
->_ElementSize
= elementSize
;
245 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
248 * \param func name of calling function used for error reporting
249 * \param attrib the attribute array index to update
250 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
251 * \param sizeMin min allowable size value
252 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
253 * \param size components per element (1, 2, 3 or 4)
254 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
255 * \param stride stride between elements, in elements
256 * \param normalized are integer types converted to floats in [-1, 1]?
257 * \param integer integer-valued values (will not be normalized to [-1,1])
258 * \param ptr the address (or offset inside VBO) of the array data
261 update_array(struct gl_context
*ctx
,
263 GLuint attrib
, GLbitfield legalTypesMask
,
264 GLint sizeMin
, GLint sizeMax
,
265 GLint size
, GLenum type
, GLsizei stride
,
266 GLboolean normalized
, GLboolean integer
,
269 struct gl_client_array
*array
;
271 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
273 * "Client vertex arrays - all vertex array attribute pointers must
274 * refer to buffer objects (section 2.9.2). The default vertex array
275 * object (the name zero) is also deprecated. Calling
276 * VertexAttribPointer when no buffer object or no vertex array object
277 * is bound will generate an INVALID_OPERATION error..."
279 * The check for VBOs is handled below.
281 if (ctx
->API
== API_OPENGL_CORE
282 && (ctx
->Array
.ArrayObj
== ctx
->Array
.DefaultArrayObj
)) {
283 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
288 if (!update_array_format(ctx
, func
, attrib
, legalTypesMask
, sizeMin
, sizeMax
,
289 size
, type
, normalized
, integer
)) {
294 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
298 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
300 * "An INVALID_OPERATION error is generated under any of the following
305 * * any of the *Pointer commands specifying the location and
306 * organization of vertex array data are called while zero is bound
307 * to the ARRAY_BUFFER buffer object binding point (see section
308 * 2.9.6), and the pointer argument is not NULL."
310 if (ptr
!= NULL
&& ctx
->Array
.ArrayObj
->ARBsemantics
&&
311 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
312 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
316 array
= &ctx
->Array
.ArrayObj
->_VertexAttrib
[attrib
];
317 array
->Stride
= stride
;
318 array
->StrideB
= stride
? stride
: array
->_ElementSize
;
319 array
->Ptr
= (const GLubyte
*) ptr
;
321 _mesa_reference_buffer_object(ctx
, &array
->BufferObj
,
322 ctx
->Array
.ArrayBufferObj
);
324 ctx
->NewState
|= _NEW_ARRAY
;
325 ctx
->Array
.ArrayObj
->NewArrays
|= VERT_BIT(attrib
);
330 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
332 GET_CURRENT_CONTEXT(ctx
);
333 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
334 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
335 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
336 DOUBLE_BIT
| HALF_BIT
|
337 UNSIGNED_INT_2_10_10_10_REV_BIT
|
338 INT_2_10_10_10_REV_BIT
);
340 FLUSH_VERTICES(ctx
, 0);
342 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
344 size
, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
349 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
351 GET_CURRENT_CONTEXT(ctx
);
352 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
353 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
354 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
355 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
356 UNSIGNED_INT_2_10_10_10_REV_BIT
|
357 INT_2_10_10_10_REV_BIT
);
359 FLUSH_VERTICES(ctx
, 0);
361 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
363 3, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
368 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
370 GET_CURRENT_CONTEXT(ctx
);
371 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
372 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
373 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
374 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
375 INT_BIT
| UNSIGNED_INT_BIT
|
376 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
377 UNSIGNED_INT_2_10_10_10_REV_BIT
|
378 INT_2_10_10_10_REV_BIT
);
379 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
381 FLUSH_VERTICES(ctx
, 0);
383 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
384 legalTypes
, sizeMin
, BGRA_OR_4
,
385 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
390 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
392 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
393 GET_CURRENT_CONTEXT(ctx
);
395 FLUSH_VERTICES(ctx
, 0);
397 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
399 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
404 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
406 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
407 FLOAT_BIT
| DOUBLE_BIT
);
408 GET_CURRENT_CONTEXT(ctx
);
410 FLUSH_VERTICES(ctx
, 0);
412 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
414 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
419 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
420 GLsizei stride
, const GLvoid
*ptr
)
422 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
423 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
424 INT_BIT
| UNSIGNED_INT_BIT
|
425 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
426 UNSIGNED_INT_2_10_10_10_REV_BIT
|
427 INT_2_10_10_10_REV_BIT
);
428 GET_CURRENT_CONTEXT(ctx
);
430 FLUSH_VERTICES(ctx
, 0);
432 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
433 legalTypes
, 3, BGRA_OR_4
,
434 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
439 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
442 GET_CURRENT_CONTEXT(ctx
);
443 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
444 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
445 : (SHORT_BIT
| INT_BIT
|
446 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
447 UNSIGNED_INT_2_10_10_10_REV_BIT
|
448 INT_2_10_10_10_REV_BIT
);
449 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
450 const GLuint unit
= ctx
->Array
.ActiveTexture
;
452 FLUSH_VERTICES(ctx
, 0);
454 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
455 legalTypes
, sizeMin
, 4,
456 size
, type
, stride
, GL_FALSE
, GL_FALSE
,
462 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
464 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
465 /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
466 const GLboolean integer
= GL_TRUE
;
467 GET_CURRENT_CONTEXT(ctx
);
469 FLUSH_VERTICES(ctx
, 0);
471 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
473 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, ptr
);
478 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
480 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
481 GET_CURRENT_CONTEXT(ctx
);
483 FLUSH_VERTICES(ctx
, 0);
485 if (ctx
->API
!= API_OPENGLES
) {
486 _mesa_error(ctx
, GL_INVALID_OPERATION
,
487 "glPointSizePointer(ES 1.x only)");
491 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
493 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
498 * Set a generic vertex attribute array.
499 * Note that these arrays DO NOT alias the conventional GL vertex arrays
500 * (position, normal, color, fog, texcoord, etc).
503 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
504 GLboolean normalized
,
505 GLsizei stride
, const GLvoid
*ptr
)
507 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
508 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
509 INT_BIT
| UNSIGNED_INT_BIT
|
510 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
511 FIXED_ES_BIT
| FIXED_GL_BIT
|
512 UNSIGNED_INT_2_10_10_10_REV_BIT
|
513 INT_2_10_10_10_REV_BIT
);
514 GET_CURRENT_CONTEXT(ctx
);
516 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
517 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
521 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
522 legalTypes
, 1, BGRA_OR_4
,
523 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
528 * GL_EXT_gpu_shader4 / GL 3.0.
529 * Set an integer-valued vertex attribute array.
530 * Note that these arrays DO NOT alias the conventional GL vertex arrays
531 * (position, normal, color, fog, texcoord, etc).
534 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
535 GLsizei stride
, const GLvoid
*ptr
)
537 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
538 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
539 INT_BIT
| UNSIGNED_INT_BIT
);
540 const GLboolean normalized
= GL_FALSE
;
541 const GLboolean integer
= GL_TRUE
;
542 GET_CURRENT_CONTEXT(ctx
);
544 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
545 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
549 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
551 size
, type
, stride
, normalized
, integer
, ptr
);
557 _mesa_EnableVertexAttribArray(GLuint index
)
559 struct gl_array_object
*arrayObj
;
560 GET_CURRENT_CONTEXT(ctx
);
562 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
563 _mesa_error(ctx
, GL_INVALID_VALUE
,
564 "glEnableVertexAttribArrayARB(index)");
568 arrayObj
= ctx
->Array
.ArrayObj
;
570 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(arrayObj
->_VertexAttrib
));
572 if (!arrayObj
->_VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
573 /* was disabled, now being enabled */
574 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
575 arrayObj
->_VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
576 arrayObj
->_Enabled
|= VERT_BIT_GENERIC(index
);
577 arrayObj
->NewArrays
|= VERT_BIT_GENERIC(index
);
583 _mesa_DisableVertexAttribArray(GLuint index
)
585 struct gl_array_object
*arrayObj
;
586 GET_CURRENT_CONTEXT(ctx
);
588 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
589 _mesa_error(ctx
, GL_INVALID_VALUE
,
590 "glDisableVertexAttribArrayARB(index)");
594 arrayObj
= ctx
->Array
.ArrayObj
;
596 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(arrayObj
->_VertexAttrib
));
598 if (arrayObj
->_VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
599 /* was enabled, now being disabled */
600 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
601 arrayObj
->_VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
602 arrayObj
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
603 arrayObj
->NewArrays
|= VERT_BIT_GENERIC(index
);
609 * Return info for a vertex attribute array (no alias with legacy
610 * vertex attributes (pos, normal, color, etc)). This function does
611 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
614 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
617 const struct gl_client_array
*array
;
619 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
620 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
624 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->_VertexAttrib
));
626 array
= &ctx
->Array
.ArrayObj
->_VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
629 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
630 return array
->Enabled
;
631 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
633 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
634 return array
->Stride
;
635 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
637 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
638 return array
->Normalized
;
639 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
640 return array
->BufferObj
->Name
;
641 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
642 if ((_mesa_is_desktop_gl(ctx
)
643 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
644 || _mesa_is_gles3(ctx
)) {
645 return array
->Integer
;
648 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
649 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
650 || _mesa_is_gles3(ctx
)) {
651 return array
->InstanceDivisor
;
659 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
664 static const GLfloat
*
665 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
668 /* In OpenGL 3.1 attribute 0 becomes non-magic, just like in OpenGL ES
669 * 2.0. Note that we cannot just check for API_OPENGL_CORE here because
670 * that will erroneously allow this usage in a 3.0 forward-compatible
673 if ((ctx
->API
!= API_OPENGL_CORE
|| ctx
->Version
< 31)
674 && ctx
->API
!= API_OPENGLES2
) {
675 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
679 else if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
680 _mesa_error(ctx
, GL_INVALID_VALUE
,
681 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
685 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->_VertexAttrib
));
687 FLUSH_CURRENT(ctx
, 0);
688 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
692 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
694 GET_CURRENT_CONTEXT(ctx
);
696 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
697 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
703 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
704 "glGetVertexAttribfv");
710 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
712 GET_CURRENT_CONTEXT(ctx
);
714 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
715 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
717 params
[0] = (GLdouble
) v
[0];
718 params
[1] = (GLdouble
) v
[1];
719 params
[2] = (GLdouble
) v
[2];
720 params
[3] = (GLdouble
) v
[3];
724 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
725 "glGetVertexAttribdv");
731 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
733 GET_CURRENT_CONTEXT(ctx
);
735 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
736 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
738 /* XXX should floats in[0,1] be scaled to full int range? */
739 params
[0] = (GLint
) v
[0];
740 params
[1] = (GLint
) v
[1];
741 params
[2] = (GLint
) v
[2];
742 params
[3] = (GLint
) v
[3];
746 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
747 "glGetVertexAttribiv");
754 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
756 GET_CURRENT_CONTEXT(ctx
);
758 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
759 const GLint
*v
= (const GLint
*)
760 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
766 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
767 "glGetVertexAttribIiv");
774 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
776 GET_CURRENT_CONTEXT(ctx
);
778 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
779 const GLuint
*v
= (const GLuint
*)
780 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
786 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
787 "glGetVertexAttribIuiv");
793 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
795 GET_CURRENT_CONTEXT(ctx
);
797 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
798 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
802 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
803 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
807 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->_VertexAttrib
));
809 *pointer
= (GLvoid
*) ctx
->Array
.ArrayObj
->_VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
814 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
815 GLsizei count
, const GLvoid
*ptr
)
818 _mesa_VertexPointer(size
, type
, stride
, ptr
);
823 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
827 _mesa_NormalPointer(type
, stride
, ptr
);
832 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
836 _mesa_ColorPointer(size
, type
, stride
, ptr
);
841 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
845 _mesa_IndexPointer(type
, stride
, ptr
);
850 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
851 GLsizei count
, const GLvoid
*ptr
)
854 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
859 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
862 _mesa_EdgeFlagPointer(stride
, ptr
);
867 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
869 GET_CURRENT_CONTEXT(ctx
);
870 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
871 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
872 GLenum ctype
= 0; /* color type */
873 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
874 const GLint toffset
= 0; /* always zero */
875 GLint defstride
; /* default stride */
878 FLUSH_VERTICES(ctx
, 0);
881 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
884 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
890 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
891 tcomps
= 0; ccomps
= 0; vcomps
= 2;
896 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
897 tcomps
= 0; ccomps
= 0; vcomps
= 3;
902 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
903 tcomps
= 0; ccomps
= 4; vcomps
= 2;
904 ctype
= GL_UNSIGNED_BYTE
;
910 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
911 tcomps
= 0; ccomps
= 4; vcomps
= 3;
912 ctype
= GL_UNSIGNED_BYTE
;
918 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
919 tcomps
= 0; ccomps
= 3; vcomps
= 3;
926 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
927 tcomps
= 0; ccomps
= 0; vcomps
= 3;
933 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
934 tcomps
= 0; ccomps
= 4; vcomps
= 3;
942 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
943 tcomps
= 2; ccomps
= 0; vcomps
= 3;
948 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
949 tcomps
= 4; ccomps
= 0; vcomps
= 4;
953 case GL_T2F_C4UB_V3F
:
954 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
955 tcomps
= 2; ccomps
= 4; vcomps
= 3;
956 ctype
= GL_UNSIGNED_BYTE
;
962 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
963 tcomps
= 2; ccomps
= 3; vcomps
= 3;
970 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
971 tcomps
= 2; ccomps
= 0; vcomps
= 3;
976 case GL_T2F_C4F_N3F_V3F
:
977 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
978 tcomps
= 2; ccomps
= 4; vcomps
= 3;
985 case GL_T4F_C4F_N3F_V4F
:
986 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
987 tcomps
= 4; ccomps
= 4; vcomps
= 4;
995 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1003 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1004 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1005 /* XXX also disable secondary color and generic arrays? */
1009 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1010 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1011 (GLubyte
*) pointer
+ toffset
);
1014 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1019 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1020 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1021 (GLubyte
*) pointer
+ coffset
);
1024 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1030 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1031 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1034 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1038 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1039 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1040 (GLubyte
*) pointer
+ voffset
);
1045 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1047 GET_CURRENT_CONTEXT(ctx
);
1049 FLUSH_VERTICES(ctx
, 0);
1051 if (MESA_VERBOSE
& VERBOSE_API
)
1052 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1055 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1059 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1062 if (ctx
->Array
.LockCount
!= 0) {
1063 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1067 ctx
->Array
.LockFirst
= first
;
1068 ctx
->Array
.LockCount
= count
;
1070 ctx
->NewState
|= _NEW_ARRAY
;
1075 _mesa_UnlockArraysEXT( void )
1077 GET_CURRENT_CONTEXT(ctx
);
1079 FLUSH_VERTICES(ctx
, 0);
1081 if (MESA_VERBOSE
& VERBOSE_API
)
1082 _mesa_debug(ctx
, "glUnlockArrays\n");
1084 if (ctx
->Array
.LockCount
== 0) {
1085 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1089 ctx
->Array
.LockFirst
= 0;
1090 ctx
->Array
.LockCount
= 0;
1091 ctx
->NewState
|= _NEW_ARRAY
;
1095 /* GL_EXT_multi_draw_arrays */
1097 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1098 const GLsizei
*count
, GLsizei primcount
)
1100 GET_CURRENT_CONTEXT(ctx
);
1103 FLUSH_VERTICES(ctx
, 0);
1105 for (i
= 0; i
< primcount
; i
++) {
1107 CALL_DrawArrays(ctx
->Exec
, (mode
, first
[i
], count
[i
]));
1113 /* GL_IBM_multimode_draw_arrays */
1115 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1116 const GLsizei
* count
,
1117 GLsizei primcount
, GLint modestride
)
1119 GET_CURRENT_CONTEXT(ctx
);
1122 FLUSH_VERTICES(ctx
, 0);
1124 for ( i
= 0 ; i
< primcount
; i
++ ) {
1125 if ( count
[i
] > 0 ) {
1126 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1127 CALL_DrawArrays(ctx
->Exec
, ( m
, first
[i
], count
[i
] ));
1133 /* GL_IBM_multimode_draw_arrays */
1135 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1136 GLenum type
, const GLvoid
* const * indices
,
1137 GLsizei primcount
, GLint modestride
)
1139 GET_CURRENT_CONTEXT(ctx
);
1142 FLUSH_VERTICES(ctx
, 0);
1144 /* XXX not sure about ARB_vertex_buffer_object handling here */
1146 for ( i
= 0 ; i
< primcount
; i
++ ) {
1147 if ( count
[i
] > 0 ) {
1148 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1149 CALL_DrawElements(ctx
->Exec
, ( m
, count
[i
], type
, indices
[i
] ));
1156 * GL_NV_primitive_restart and GL 3.1
1159 _mesa_PrimitiveRestartIndex(GLuint index
)
1161 GET_CURRENT_CONTEXT(ctx
);
1163 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1164 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1168 if (ctx
->Array
.RestartIndex
!= index
) {
1169 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1170 ctx
->Array
.RestartIndex
= index
;
1176 * See GL_ARB_instanced_arrays.
1177 * Note that the instance divisor only applies to generic arrays, not
1178 * the legacy vertex arrays.
1181 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1183 struct gl_client_array
*array
;
1184 GET_CURRENT_CONTEXT(ctx
);
1186 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1187 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1191 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
1192 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1197 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->_VertexAttrib
));
1199 array
= &ctx
->Array
.ArrayObj
->_VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
1200 if (array
->InstanceDivisor
!= divisor
) {
1201 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
1202 array
->InstanceDivisor
= divisor
;
1203 ctx
->Array
.ArrayObj
->NewArrays
|= VERT_BIT(VERT_ATTRIB_GENERIC(index
));
1209 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1211 /* From the OpenGL 4.3 core specification, page 302:
1212 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1213 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1216 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1218 case GL_UNSIGNED_BYTE
:
1220 case GL_UNSIGNED_SHORT
:
1222 case GL_UNSIGNED_INT
:
1225 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1229 return ctx
->Array
.RestartIndex
;
1234 * GL_ARB_vertex_attrib_binding
1237 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1244 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1245 GLboolean normalized
, GLuint relativeOffset
)
1251 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1252 GLuint relativeOffset
)
1258 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
1259 GLuint relativeOffset
)
1265 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
1271 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
1277 * Copy one client vertex array to another.
1280 _mesa_copy_client_array(struct gl_context
*ctx
,
1281 struct gl_client_array
*dst
,
1282 struct gl_client_array
*src
)
1284 dst
->Size
= src
->Size
;
1285 dst
->Type
= src
->Type
;
1286 dst
->Format
= src
->Format
;
1287 dst
->Stride
= src
->Stride
;
1288 dst
->StrideB
= src
->StrideB
;
1289 dst
->Ptr
= src
->Ptr
;
1290 dst
->Enabled
= src
->Enabled
;
1291 dst
->Normalized
= src
->Normalized
;
1292 dst
->Integer
= src
->Integer
;
1293 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1294 dst
->_ElementSize
= src
->_ElementSize
;
1295 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1296 dst
->_MaxElement
= src
->_MaxElement
;
1302 * Print vertex array's fields.
1305 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1308 printf(" %s[%d]: ", name
, index
);
1310 printf(" %s: ", name
);
1311 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
1312 array
->Ptr
, array
->Type
, array
->Size
,
1313 array
->_ElementSize
, array
->StrideB
,
1314 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
,
1315 array
->_MaxElement
);
1320 * Print current vertex object/array info. For debug.
1323 _mesa_print_arrays(struct gl_context
*ctx
)
1325 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
1328 _mesa_update_array_object_max_element(ctx
, arrayObj
);
1330 printf("Array Object %u\n", arrayObj
->Name
);
1331 if (arrayObj
->_VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
1332 print_array("Vertex", -1, &arrayObj
->_VertexAttrib
[VERT_ATTRIB_POS
]);
1333 if (arrayObj
->_VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
1334 print_array("Normal", -1, &arrayObj
->_VertexAttrib
[VERT_ATTRIB_NORMAL
]);
1335 if (arrayObj
->_VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
1336 print_array("Color", -1, &arrayObj
->_VertexAttrib
[VERT_ATTRIB_COLOR0
]);
1337 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
1338 if (arrayObj
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
1339 print_array("TexCoord", i
, &arrayObj
->_VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
1340 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
1341 if (arrayObj
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
1342 print_array("Attrib", i
, &arrayObj
->_VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
1343 printf(" _MaxElement = %u\n", arrayObj
->_MaxElement
);
1348 * Initialize vertex array state for given context.
1351 _mesa_init_varray(struct gl_context
*ctx
)
1353 ctx
->Array
.DefaultArrayObj
= ctx
->Driver
.NewArrayObject(ctx
, 0);
1354 _mesa_reference_array_object(ctx
, &ctx
->Array
.ArrayObj
,
1355 ctx
->Array
.DefaultArrayObj
);
1356 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1358 ctx
->Array
.Objects
= _mesa_NewHashTable();
1363 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1366 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1368 struct gl_array_object
*arrayObj
= (struct gl_array_object
*) data
;
1369 struct gl_context
*ctx
= (struct gl_context
*) userData
;
1370 _mesa_delete_array_object(ctx
, arrayObj
);
1375 * Free vertex array state for given context.
1378 _mesa_free_varray_data(struct gl_context
*ctx
)
1380 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1381 _mesa_DeleteHashTable(ctx
->Array
.Objects
);