2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #include "bufferobj.h"
36 #include "mfeatures.h"
40 #include "main/dispatch.h"
43 /** Used to do error checking for GL_EXT_vertex_array_bgra */
47 /** Used to indicate which GL datatypes are accepted by each of the
48 * glVertex/Color/Attrib/EtcPointer() functions.
52 #define UNSIGNED_BYTE_BIT 0x4
54 #define UNSIGNED_SHORT_BIT 0x10
56 #define UNSIGNED_INT_BIT 0x40
58 #define FLOAT_BIT 0x100
59 #define DOUBLE_BIT 0x200
60 #define FIXED_ES_BIT 0x400
61 #define FIXED_GL_BIT 0x800
62 #define UNSIGNED_INT_2_10_10_10_REV_BIT 0x1000
63 #define INT_2_10_10_10_REV_BIT 0x2000
66 /** Convert GL datatype enum into a <type>_BIT value seen above */
68 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
75 case GL_UNSIGNED_BYTE
:
76 return UNSIGNED_BYTE_BIT
;
79 case GL_UNSIGNED_SHORT
:
80 return UNSIGNED_SHORT_BIT
;
84 return UNSIGNED_INT_BIT
;
86 if (ctx
->Extensions
.ARB_half_float_vertex
)
95 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
96 case GL_UNSIGNED_INT_2_10_10_10_REV
:
97 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
98 case GL_INT_2_10_10_10_REV
:
99 return INT_2_10_10_10_REV_BIT
;
107 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
110 * \param func name of calling function used for error reporting
111 * \param attrib the attribute array index to update
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 stride stride between elements, in elements
118 * \param normalized are integer types converted to floats in [-1, 1]?
119 * \param integer integer-valued values (will not be normalized to [-1,1])
120 * \param ptr the address (or offset inside VBO) of the array data
123 update_array(struct gl_context
*ctx
,
125 GLuint attrib
, GLbitfield legalTypesMask
,
126 GLint sizeMin
, GLint sizeMax
,
127 GLint size
, GLenum type
, GLsizei stride
,
128 GLboolean normalized
, GLboolean integer
,
131 struct gl_client_array
*array
;
134 GLenum format
= GL_RGBA
;
136 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
138 * "Client vertex arrays - all vertex array attribute pointers must
139 * refer to buffer objects (section 2.9.2). The default vertex array
140 * object (the name zero) is also deprecated. Calling
141 * VertexAttribPointer when no buffer object or no vertex array object
142 * is bound will generate an INVALID_OPERATION error..."
144 * The check for VBOs is handled below.
146 if (ctx
->API
== API_OPENGL_CORE
147 && (ctx
->Array
.ArrayObj
== ctx
->Array
.DefaultArrayObj
)) {
148 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
153 if (_mesa_is_gles(ctx
)) {
154 /* Once Mesa gets support for GL_OES_vertex_half_float this mask will
155 * change. Adding support for this extension isn't quite as trivial as
156 * we'd like because ES uses a different enum value for GL_HALF_FLOAT.
158 legalTypesMask
&= ~(FIXED_GL_BIT
| HALF_BIT
| DOUBLE_BIT
);
160 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
161 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
162 * GL_OES_vertex_type_10_10_10_2.
164 if (ctx
->Version
< 30) {
165 legalTypesMask
&= ~(UNSIGNED_INT_BIT
167 | UNSIGNED_INT_2_10_10_10_REV_BIT
168 | INT_2_10_10_10_REV_BIT
);
171 /* BGRA ordering is not supported in ES contexts.
173 if (sizeMax
== BGRA_OR_4
)
176 legalTypesMask
&= ~FIXED_ES_BIT
;
178 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
179 legalTypesMask
&= ~FIXED_GL_BIT
;
181 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
182 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
183 INT_2_10_10_10_REV_BIT
);
186 typeBit
= type_to_bit(ctx
, type
);
187 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
188 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
189 func
, _mesa_lookup_enum_by_nr(type
));
193 /* Do size parameter checking.
194 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
195 * must be handled specially.
197 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
198 sizeMax
== BGRA_OR_4
&&
200 GLboolean bgra_error
= GL_FALSE
;
202 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
203 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
204 type
!= GL_INT_2_10_10_10_REV
&&
205 type
!= GL_UNSIGNED_BYTE
)
206 bgra_error
= GL_TRUE
;
207 } else if (type
!= GL_UNSIGNED_BYTE
)
208 bgra_error
= GL_TRUE
;
211 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(GL_BGRA/GLubyte)", func
);
217 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
218 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
222 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
223 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
224 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
225 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
232 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
236 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
238 * "An INVALID_OPERATION error is generated under any of the following
243 * * any of the *Pointer commands specifying the location and
244 * organization of vertex array data are called while zero is bound
245 * to the ARRAY_BUFFER buffer object binding point (see section
246 * 2.9.6), and the pointer argument is not NULL."
248 if (ptr
!= NULL
&& ctx
->Array
.ArrayObj
->ARBsemantics
&&
249 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
250 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
254 elementSize
= _mesa_sizeof_type(type
) * size
;
256 array
= &ctx
->Array
.ArrayObj
->VertexAttrib
[attrib
];
259 array
->Format
= format
;
260 array
->Stride
= stride
;
261 array
->StrideB
= stride
? stride
: elementSize
;
262 array
->Normalized
= normalized
;
263 array
->Integer
= integer
;
264 array
->Ptr
= (const GLubyte
*) ptr
;
265 array
->_ElementSize
= elementSize
;
267 _mesa_reference_buffer_object(ctx
, &array
->BufferObj
,
268 ctx
->Array
.ArrayBufferObj
);
270 ctx
->NewState
|= _NEW_ARRAY
;
271 ctx
->Array
.ArrayObj
->NewArrays
|= VERT_BIT(attrib
);
276 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
278 GET_CURRENT_CONTEXT(ctx
);
279 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
280 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
281 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
282 DOUBLE_BIT
| HALF_BIT
|
283 UNSIGNED_INT_2_10_10_10_REV_BIT
|
284 INT_2_10_10_10_REV_BIT
);
285 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
287 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
289 size
, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
294 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
296 GET_CURRENT_CONTEXT(ctx
);
297 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
298 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
299 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
300 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
301 UNSIGNED_INT_2_10_10_10_REV_BIT
|
302 INT_2_10_10_10_REV_BIT
);
303 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
305 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
307 3, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
312 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
314 GET_CURRENT_CONTEXT(ctx
);
315 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
316 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
317 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
318 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
319 INT_BIT
| UNSIGNED_INT_BIT
|
320 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
321 UNSIGNED_INT_2_10_10_10_REV_BIT
|
322 INT_2_10_10_10_REV_BIT
);
323 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
324 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
326 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
327 legalTypes
, sizeMin
, BGRA_OR_4
,
328 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
333 _mesa_FogCoordPointerEXT(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
335 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
336 GET_CURRENT_CONTEXT(ctx
);
337 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
339 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
341 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
346 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
348 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
349 FLOAT_BIT
| DOUBLE_BIT
);
350 GET_CURRENT_CONTEXT(ctx
);
351 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
353 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
355 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
360 _mesa_SecondaryColorPointerEXT(GLint size
, GLenum type
,
361 GLsizei stride
, const GLvoid
*ptr
)
363 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
364 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
365 INT_BIT
| UNSIGNED_INT_BIT
|
366 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
367 UNSIGNED_INT_2_10_10_10_REV_BIT
|
368 INT_2_10_10_10_REV_BIT
);
369 GET_CURRENT_CONTEXT(ctx
);
370 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
372 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
373 legalTypes
, 3, BGRA_OR_4
,
374 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
379 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
382 GET_CURRENT_CONTEXT(ctx
);
383 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
384 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
385 : (SHORT_BIT
| INT_BIT
|
386 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
387 UNSIGNED_INT_2_10_10_10_REV_BIT
|
388 INT_2_10_10_10_REV_BIT
);
389 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
390 const GLuint unit
= ctx
->Array
.ActiveTexture
;
391 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
393 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
394 legalTypes
, sizeMin
, 4,
395 size
, type
, stride
, GL_FALSE
, GL_FALSE
,
401 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
403 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
404 /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
405 const GLboolean integer
= GL_TRUE
;
406 GET_CURRENT_CONTEXT(ctx
);
407 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
409 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
411 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, ptr
);
416 _mesa_PointSizePointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
418 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
419 GET_CURRENT_CONTEXT(ctx
);
420 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
422 if (ctx
->API
!= API_OPENGLES
) {
423 _mesa_error(ctx
, GL_INVALID_OPERATION
,
424 "glPointSizePointer(ES 1.x only)");
428 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
430 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
435 * Set a vertex attribute array.
436 * Note that these arrays DO alias the conventional GL vertex arrays
437 * (position, normal, color, fog, texcoord, etc).
438 * The generic attribute slots at #16 and above are not touched.
441 _mesa_VertexAttribPointerNV(GLuint index
, GLint size
, GLenum type
,
442 GLsizei stride
, const GLvoid
*ptr
)
444 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
|
445 FLOAT_BIT
| DOUBLE_BIT
);
446 GLboolean normalized
= GL_FALSE
;
447 GET_CURRENT_CONTEXT(ctx
);
448 ASSERT_OUTSIDE_BEGIN_END(ctx
);
450 if (index
>= MAX_NV_VERTEX_PROGRAM_INPUTS
) {
451 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(index)");
455 if (type
== GL_UNSIGNED_BYTE
&& size
!= 4) {
456 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(size!=4)");
460 update_array(ctx
, "glVertexAttribPointerNV", VERT_ATTRIB_GENERIC(index
),
461 legalTypes
, 1, BGRA_OR_4
,
462 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
466 #if FEATURE_ARB_vertex_program
468 * Set a generic vertex attribute array.
469 * Note that these arrays DO NOT alias the conventional GL vertex arrays
470 * (position, normal, color, fog, texcoord, etc).
473 _mesa_VertexAttribPointerARB(GLuint index
, GLint size
, GLenum type
,
474 GLboolean normalized
,
475 GLsizei stride
, const GLvoid
*ptr
)
477 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
478 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
479 INT_BIT
| UNSIGNED_INT_BIT
|
480 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
481 FIXED_ES_BIT
| FIXED_GL_BIT
|
482 UNSIGNED_INT_2_10_10_10_REV_BIT
|
483 INT_2_10_10_10_REV_BIT
);
484 GET_CURRENT_CONTEXT(ctx
);
485 ASSERT_OUTSIDE_BEGIN_END(ctx
);
487 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
488 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
492 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
493 legalTypes
, 1, BGRA_OR_4
,
494 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
500 * GL_EXT_gpu_shader4 / GL 3.0.
501 * Set an integer-valued vertex attribute array.
502 * Note that these arrays DO NOT alias the conventional GL vertex arrays
503 * (position, normal, color, fog, texcoord, etc).
506 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
507 GLsizei stride
, const GLvoid
*ptr
)
509 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
510 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
511 INT_BIT
| UNSIGNED_INT_BIT
);
512 const GLboolean normalized
= GL_FALSE
;
513 const GLboolean integer
= GL_TRUE
;
514 GET_CURRENT_CONTEXT(ctx
);
515 ASSERT_OUTSIDE_BEGIN_END(ctx
);
517 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
518 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
522 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
524 size
, type
, stride
, normalized
, integer
, ptr
);
530 _mesa_EnableVertexAttribArrayARB(GLuint index
)
532 struct gl_array_object
*arrayObj
;
533 GET_CURRENT_CONTEXT(ctx
);
534 ASSERT_OUTSIDE_BEGIN_END(ctx
);
536 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
537 _mesa_error(ctx
, GL_INVALID_VALUE
,
538 "glEnableVertexAttribArrayARB(index)");
542 arrayObj
= ctx
->Array
.ArrayObj
;
544 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(arrayObj
->VertexAttrib
));
546 if (!arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
547 /* was disabled, now being enabled */
548 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
549 arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
550 arrayObj
->_Enabled
|= VERT_BIT_GENERIC(index
);
551 arrayObj
->NewArrays
|= VERT_BIT_GENERIC(index
);
557 _mesa_DisableVertexAttribArrayARB(GLuint index
)
559 struct gl_array_object
*arrayObj
;
560 GET_CURRENT_CONTEXT(ctx
);
561 ASSERT_OUTSIDE_BEGIN_END(ctx
);
563 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
564 _mesa_error(ctx
, GL_INVALID_VALUE
,
565 "glDisableVertexAttribArrayARB(index)");
569 arrayObj
= ctx
->Array
.ArrayObj
;
571 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(arrayObj
->VertexAttrib
));
573 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
574 /* was enabled, now being disabled */
575 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
576 arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
577 arrayObj
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
578 arrayObj
->NewArrays
|= VERT_BIT_GENERIC(index
);
584 * Return info for a vertex attribute array (no alias with legacy
585 * vertex attributes (pos, normal, color, etc)). This function does
586 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
589 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
592 const struct gl_client_array
*array
;
594 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
595 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
599 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
601 array
= &ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
604 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
605 return array
->Enabled
;
606 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
608 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
609 return array
->Stride
;
610 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
612 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
613 return array
->Normalized
;
614 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
615 return array
->BufferObj
->Name
;
616 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
617 if ((_mesa_is_desktop_gl(ctx
)
618 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
619 || _mesa_is_gles3(ctx
)) {
620 return array
->Integer
;
623 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
624 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
625 || _mesa_is_gles3(ctx
)) {
626 return array
->InstanceDivisor
;
634 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
639 static const GLfloat
*
640 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
643 /* In OpenGL 3.1 attribute 0 becomes non-magic, just like in OpenGL ES
644 * 2.0. Note that we cannot just check for API_OPENGL_CORE here because
645 * that will erroneously allow this usage in a 3.0 forward-compatible
648 if ((ctx
->API
!= API_OPENGL_CORE
|| ctx
->Version
< 31)
649 && ctx
->API
!= API_OPENGLES2
) {
650 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
654 else if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
655 _mesa_error(ctx
, GL_INVALID_VALUE
,
656 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
660 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
662 FLUSH_CURRENT(ctx
, 0);
663 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
667 _mesa_GetVertexAttribfvARB(GLuint index
, GLenum pname
, GLfloat
*params
)
669 GET_CURRENT_CONTEXT(ctx
);
670 ASSERT_OUTSIDE_BEGIN_END(ctx
);
672 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
673 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
679 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
680 "glGetVertexAttribfv");
686 _mesa_GetVertexAttribdvARB(GLuint index
, GLenum pname
, GLdouble
*params
)
688 GET_CURRENT_CONTEXT(ctx
);
689 ASSERT_OUTSIDE_BEGIN_END(ctx
);
691 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
692 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
694 params
[0] = (GLdouble
) v
[0];
695 params
[1] = (GLdouble
) v
[1];
696 params
[2] = (GLdouble
) v
[2];
697 params
[3] = (GLdouble
) v
[3];
701 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
702 "glGetVertexAttribdv");
708 _mesa_GetVertexAttribivARB(GLuint index
, GLenum pname
, GLint
*params
)
710 GET_CURRENT_CONTEXT(ctx
);
711 ASSERT_OUTSIDE_BEGIN_END(ctx
);
713 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
714 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
716 /* XXX should floats in[0,1] be scaled to full int range? */
717 params
[0] = (GLint
) v
[0];
718 params
[1] = (GLint
) v
[1];
719 params
[2] = (GLint
) v
[2];
720 params
[3] = (GLint
) v
[3];
724 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
725 "glGetVertexAttribiv");
732 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
734 GET_CURRENT_CONTEXT(ctx
);
735 ASSERT_OUTSIDE_BEGIN_END(ctx
);
737 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
739 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
741 /* XXX we don't have true integer-valued vertex attribs yet */
742 params
[0] = (GLint
) v
[0];
743 params
[1] = (GLint
) v
[1];
744 params
[2] = (GLint
) v
[2];
745 params
[3] = (GLint
) v
[3];
749 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
750 "glGetVertexAttribIiv");
757 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
759 GET_CURRENT_CONTEXT(ctx
);
760 ASSERT_OUTSIDE_BEGIN_END(ctx
);
762 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
764 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
766 /* XXX we don't have true integer-valued vertex attribs yet */
767 params
[0] = (GLuint
) v
[0];
768 params
[1] = (GLuint
) v
[1];
769 params
[2] = (GLuint
) v
[2];
770 params
[3] = (GLuint
) v
[3];
774 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
775 "glGetVertexAttribIuiv");
781 _mesa_GetVertexAttribPointervARB(GLuint index
, GLenum pname
, GLvoid
**pointer
)
783 GET_CURRENT_CONTEXT(ctx
);
784 ASSERT_OUTSIDE_BEGIN_END(ctx
);
786 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
787 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
791 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
792 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
796 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
798 *pointer
= (GLvoid
*) ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
803 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
804 GLsizei count
, const GLvoid
*ptr
)
807 _mesa_VertexPointer(size
, type
, stride
, ptr
);
812 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
816 _mesa_NormalPointer(type
, stride
, ptr
);
821 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
825 _mesa_ColorPointer(size
, type
, stride
, ptr
);
830 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
834 _mesa_IndexPointer(type
, stride
, ptr
);
839 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
840 GLsizei count
, const GLvoid
*ptr
)
843 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
848 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
851 _mesa_EdgeFlagPointer(stride
, ptr
);
856 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
858 GET_CURRENT_CONTEXT(ctx
);
859 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
860 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
861 GLenum ctype
= 0; /* color type */
862 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
863 const GLint toffset
= 0; /* always zero */
864 GLint defstride
; /* default stride */
867 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
870 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
873 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
879 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
880 tcomps
= 0; ccomps
= 0; vcomps
= 2;
885 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
886 tcomps
= 0; ccomps
= 0; vcomps
= 3;
891 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
892 tcomps
= 0; ccomps
= 4; vcomps
= 2;
893 ctype
= GL_UNSIGNED_BYTE
;
899 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
900 tcomps
= 0; ccomps
= 4; vcomps
= 3;
901 ctype
= GL_UNSIGNED_BYTE
;
907 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
908 tcomps
= 0; ccomps
= 3; vcomps
= 3;
915 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
916 tcomps
= 0; ccomps
= 0; vcomps
= 3;
922 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
923 tcomps
= 0; ccomps
= 4; vcomps
= 3;
931 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
932 tcomps
= 2; ccomps
= 0; vcomps
= 3;
937 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
938 tcomps
= 4; ccomps
= 0; vcomps
= 4;
942 case GL_T2F_C4UB_V3F
:
943 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
944 tcomps
= 2; ccomps
= 4; vcomps
= 3;
945 ctype
= GL_UNSIGNED_BYTE
;
951 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
952 tcomps
= 2; ccomps
= 3; vcomps
= 3;
959 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
960 tcomps
= 2; ccomps
= 0; vcomps
= 3;
965 case GL_T2F_C4F_N3F_V3F
:
966 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
967 tcomps
= 2; ccomps
= 4; vcomps
= 3;
974 case GL_T4F_C4F_N3F_V4F
:
975 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
976 tcomps
= 4; ccomps
= 4; vcomps
= 4;
984 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
992 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
993 _mesa_DisableClientState( GL_INDEX_ARRAY
);
994 /* XXX also disable secondary color and generic arrays? */
998 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
999 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1000 (GLubyte
*) pointer
+ toffset
);
1003 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1008 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1009 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1010 (GLubyte
*) pointer
+ coffset
);
1013 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1019 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1020 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1023 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1027 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1028 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1029 (GLubyte
*) pointer
+ voffset
);
1034 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1036 GET_CURRENT_CONTEXT(ctx
);
1037 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1039 if (MESA_VERBOSE
& VERBOSE_API
)
1040 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1043 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1047 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1050 if (ctx
->Array
.LockCount
!= 0) {
1051 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1055 ctx
->Array
.LockFirst
= first
;
1056 ctx
->Array
.LockCount
= count
;
1058 ctx
->NewState
|= _NEW_ARRAY
;
1063 _mesa_UnlockArraysEXT( void )
1065 GET_CURRENT_CONTEXT(ctx
);
1066 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1068 if (MESA_VERBOSE
& VERBOSE_API
)
1069 _mesa_debug(ctx
, "glUnlockArrays\n");
1071 if (ctx
->Array
.LockCount
== 0) {
1072 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1076 ctx
->Array
.LockFirst
= 0;
1077 ctx
->Array
.LockCount
= 0;
1078 ctx
->NewState
|= _NEW_ARRAY
;
1082 /* GL_EXT_multi_draw_arrays */
1084 _mesa_MultiDrawArraysEXT( GLenum mode
, const GLint
*first
,
1085 const GLsizei
*count
, GLsizei primcount
)
1087 GET_CURRENT_CONTEXT(ctx
);
1090 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1092 for (i
= 0; i
< primcount
; i
++) {
1094 CALL_DrawArrays(ctx
->Exec
, (mode
, first
[i
], count
[i
]));
1100 /* GL_IBM_multimode_draw_arrays */
1102 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1103 const GLsizei
* count
,
1104 GLsizei primcount
, GLint modestride
)
1106 GET_CURRENT_CONTEXT(ctx
);
1109 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1111 for ( i
= 0 ; i
< primcount
; i
++ ) {
1112 if ( count
[i
] > 0 ) {
1113 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1114 CALL_DrawArrays(ctx
->Exec
, ( m
, first
[i
], count
[i
] ));
1120 /* GL_IBM_multimode_draw_arrays */
1122 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1123 GLenum type
, const GLvoid
* const * indices
,
1124 GLsizei primcount
, GLint modestride
)
1126 GET_CURRENT_CONTEXT(ctx
);
1129 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1131 /* XXX not sure about ARB_vertex_buffer_object handling here */
1133 for ( i
= 0 ; i
< primcount
; i
++ ) {
1134 if ( count
[i
] > 0 ) {
1135 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1136 CALL_DrawElements(ctx
->Exec
, ( m
, count
[i
], type
, indices
[i
] ));
1143 * GL_NV_primitive_restart and GL 3.1
1146 _mesa_PrimitiveRestartIndex(GLuint index
)
1148 GET_CURRENT_CONTEXT(ctx
);
1150 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1151 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1155 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1157 if (ctx
->Array
.RestartIndex
!= index
) {
1158 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1159 ctx
->Array
.RestartIndex
= index
;
1165 * See GL_ARB_instanced_arrays.
1166 * Note that the instance divisor only applies to generic arrays, not
1167 * the legacy vertex arrays.
1170 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1172 struct gl_client_array
*array
;
1173 GET_CURRENT_CONTEXT(ctx
);
1174 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1176 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1177 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1181 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
1182 _mesa_error(ctx
, GL_INVALID_ENUM
, "glVertexAttribDivisor(index = %u)",
1187 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
1189 array
= &ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
1190 if (array
->InstanceDivisor
!= divisor
) {
1191 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
1192 array
->InstanceDivisor
= divisor
;
1193 ctx
->Array
.ArrayObj
->NewArrays
|= VERT_BIT(VERT_ATTRIB_GENERIC(index
));
1200 * Copy one client vertex array to another.
1203 _mesa_copy_client_array(struct gl_context
*ctx
,
1204 struct gl_client_array
*dst
,
1205 struct gl_client_array
*src
)
1207 dst
->Size
= src
->Size
;
1208 dst
->Type
= src
->Type
;
1209 dst
->Format
= src
->Format
;
1210 dst
->Stride
= src
->Stride
;
1211 dst
->StrideB
= src
->StrideB
;
1212 dst
->Ptr
= src
->Ptr
;
1213 dst
->Enabled
= src
->Enabled
;
1214 dst
->Normalized
= src
->Normalized
;
1215 dst
->Integer
= src
->Integer
;
1216 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1217 dst
->_ElementSize
= src
->_ElementSize
;
1218 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1219 dst
->_MaxElement
= src
->_MaxElement
;
1225 * Print vertex array's fields.
1228 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1231 printf(" %s[%d]: ", name
, index
);
1233 printf(" %s: ", name
);
1234 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
1235 array
->Ptr
, array
->Type
, array
->Size
,
1236 array
->_ElementSize
, array
->StrideB
,
1237 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
,
1238 array
->_MaxElement
);
1243 * Print current vertex object/array info. For debug.
1246 _mesa_print_arrays(struct gl_context
*ctx
)
1248 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
1251 _mesa_update_array_object_max_element(ctx
, arrayObj
);
1253 printf("Array Object %u\n", arrayObj
->Name
);
1254 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
1255 print_array("Vertex", -1, &arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
]);
1256 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
1257 print_array("Normal", -1, &arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
]);
1258 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
1259 print_array("Color", -1, &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
]);
1260 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
1261 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
1262 print_array("TexCoord", i
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
1263 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
1264 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
1265 print_array("Attrib", i
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
1266 printf(" _MaxElement = %u\n", arrayObj
->_MaxElement
);
1271 * Initialize vertex array state for given context.
1274 _mesa_init_varray(struct gl_context
*ctx
)
1276 ctx
->Array
.DefaultArrayObj
= ctx
->Driver
.NewArrayObject(ctx
, 0);
1277 _mesa_reference_array_object(ctx
, &ctx
->Array
.ArrayObj
,
1278 ctx
->Array
.DefaultArrayObj
);
1279 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1281 ctx
->Array
.Objects
= _mesa_NewHashTable();
1286 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1289 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1291 struct gl_array_object
*arrayObj
= (struct gl_array_object
*) data
;
1292 struct gl_context
*ctx
= (struct gl_context
*) userData
;
1293 _mesa_delete_array_object(ctx
, arrayObj
);
1298 * Free vertex array state for given context.
1301 _mesa_free_varray_data(struct gl_context
*ctx
)
1303 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1304 _mesa_DeleteHashTable(ctx
->Array
.Objects
);