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 if (_mesa_is_gles(ctx
)) {
137 /* Once Mesa gets support for GL_OES_vertex_half_float this mask will
138 * change. Adding support for this extension isn't quite as trivial as
139 * we'd like because ES uses a different enum value for GL_HALF_FLOAT.
141 legalTypesMask
&= ~(FIXED_GL_BIT
| HALF_BIT
| DOUBLE_BIT
);
143 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
144 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
145 * GL_OES_vertex_type_10_10_10_2.
147 if (ctx
->Version
< 30) {
148 legalTypesMask
&= ~(UNSIGNED_INT_BIT
150 | UNSIGNED_INT_2_10_10_10_REV_BIT
151 | INT_2_10_10_10_REV_BIT
);
154 /* BGRA ordering is not supported in ES contexts.
156 if (sizeMax
== BGRA_OR_4
)
159 legalTypesMask
&= ~FIXED_ES_BIT
;
161 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
162 legalTypesMask
&= ~FIXED_GL_BIT
;
164 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
165 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
166 INT_2_10_10_10_REV_BIT
);
169 typeBit
= type_to_bit(ctx
, type
);
170 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
171 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
172 func
, _mesa_lookup_enum_by_nr(type
));
176 /* Do size parameter checking.
177 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
178 * must be handled specially.
180 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
181 sizeMax
== BGRA_OR_4
&&
183 GLboolean bgra_error
= GL_FALSE
;
185 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
186 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
187 type
!= GL_INT_2_10_10_10_REV
&&
188 type
!= GL_UNSIGNED_BYTE
)
189 bgra_error
= GL_TRUE
;
190 } else if (type
!= GL_UNSIGNED_BYTE
)
191 bgra_error
= GL_TRUE
;
194 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(GL_BGRA/GLubyte)", func
);
200 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
201 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
205 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
206 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
207 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
208 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
215 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
219 if (ctx
->Array
.ArrayObj
->ARBsemantics
&&
220 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
221 /* GL_ARB_vertex_array_object requires that all arrays reside in VBOs.
222 * Generate GL_INVALID_OPERATION if that's not true.
224 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
228 elementSize
= _mesa_sizeof_type(type
) * size
;
230 array
= &ctx
->Array
.ArrayObj
->VertexAttrib
[attrib
];
233 array
->Format
= format
;
234 array
->Stride
= stride
;
235 array
->StrideB
= stride
? stride
: elementSize
;
236 array
->Normalized
= normalized
;
237 array
->Integer
= integer
;
238 array
->Ptr
= (const GLubyte
*) ptr
;
239 array
->_ElementSize
= elementSize
;
241 _mesa_reference_buffer_object(ctx
, &array
->BufferObj
,
242 ctx
->Array
.ArrayBufferObj
);
244 ctx
->NewState
|= _NEW_ARRAY
;
245 ctx
->Array
.ArrayObj
->NewArrays
|= VERT_BIT(attrib
);
250 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
252 GET_CURRENT_CONTEXT(ctx
);
253 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
254 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
255 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
256 DOUBLE_BIT
| HALF_BIT
|
257 UNSIGNED_INT_2_10_10_10_REV_BIT
|
258 INT_2_10_10_10_REV_BIT
);
259 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
261 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
263 size
, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
268 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
270 GET_CURRENT_CONTEXT(ctx
);
271 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
272 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
273 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
274 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
275 UNSIGNED_INT_2_10_10_10_REV_BIT
|
276 INT_2_10_10_10_REV_BIT
);
277 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
279 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
281 3, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
286 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
288 GET_CURRENT_CONTEXT(ctx
);
289 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
290 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
291 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
292 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
293 INT_BIT
| UNSIGNED_INT_BIT
|
294 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
295 UNSIGNED_INT_2_10_10_10_REV_BIT
|
296 INT_2_10_10_10_REV_BIT
);
297 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
298 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
300 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
301 legalTypes
, sizeMin
, BGRA_OR_4
,
302 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
307 _mesa_FogCoordPointerEXT(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
309 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
310 GET_CURRENT_CONTEXT(ctx
);
311 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
313 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
315 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
320 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
322 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
323 FLOAT_BIT
| DOUBLE_BIT
);
324 GET_CURRENT_CONTEXT(ctx
);
325 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
327 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
329 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
334 _mesa_SecondaryColorPointerEXT(GLint size
, GLenum type
,
335 GLsizei stride
, const GLvoid
*ptr
)
337 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
338 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
339 INT_BIT
| UNSIGNED_INT_BIT
|
340 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
341 UNSIGNED_INT_2_10_10_10_REV_BIT
|
342 INT_2_10_10_10_REV_BIT
);
343 GET_CURRENT_CONTEXT(ctx
);
344 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
346 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
347 legalTypes
, 3, BGRA_OR_4
,
348 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
353 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
356 GET_CURRENT_CONTEXT(ctx
);
357 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
358 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
359 : (SHORT_BIT
| INT_BIT
|
360 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
361 UNSIGNED_INT_2_10_10_10_REV_BIT
|
362 INT_2_10_10_10_REV_BIT
);
363 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
364 const GLuint unit
= ctx
->Array
.ActiveTexture
;
365 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
367 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
368 legalTypes
, sizeMin
, 4,
369 size
, type
, stride
, GL_FALSE
, GL_FALSE
,
375 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
377 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
378 /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
379 const GLboolean integer
= GL_TRUE
;
380 GET_CURRENT_CONTEXT(ctx
);
381 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
383 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
385 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, ptr
);
390 _mesa_PointSizePointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
392 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
393 GET_CURRENT_CONTEXT(ctx
);
394 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
396 if (ctx
->API
!= API_OPENGLES
) {
397 _mesa_error(ctx
, GL_INVALID_OPERATION
,
398 "glPointSizePointer(ES 1.x only)");
402 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
404 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
408 #if FEATURE_NV_vertex_program
410 * Set a vertex attribute array.
411 * Note that these arrays DO alias the conventional GL vertex arrays
412 * (position, normal, color, fog, texcoord, etc).
413 * The generic attribute slots at #16 and above are not touched.
416 _mesa_VertexAttribPointerNV(GLuint index
, GLint size
, GLenum type
,
417 GLsizei stride
, const GLvoid
*ptr
)
419 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
|
420 FLOAT_BIT
| DOUBLE_BIT
);
421 GLboolean normalized
= GL_FALSE
;
422 GET_CURRENT_CONTEXT(ctx
);
423 ASSERT_OUTSIDE_BEGIN_END(ctx
);
425 if (index
>= MAX_NV_VERTEX_PROGRAM_INPUTS
) {
426 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(index)");
430 if (type
== GL_UNSIGNED_BYTE
&& size
!= 4) {
431 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(size!=4)");
435 update_array(ctx
, "glVertexAttribPointerNV", VERT_ATTRIB_GENERIC(index
),
436 legalTypes
, 1, BGRA_OR_4
,
437 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
442 #if FEATURE_ARB_vertex_program
444 * Set a generic vertex attribute array.
445 * Note that these arrays DO NOT alias the conventional GL vertex arrays
446 * (position, normal, color, fog, texcoord, etc).
449 _mesa_VertexAttribPointerARB(GLuint index
, GLint size
, GLenum type
,
450 GLboolean normalized
,
451 GLsizei stride
, const GLvoid
*ptr
)
453 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
454 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
455 INT_BIT
| UNSIGNED_INT_BIT
|
456 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
457 FIXED_ES_BIT
| FIXED_GL_BIT
|
458 UNSIGNED_INT_2_10_10_10_REV_BIT
|
459 INT_2_10_10_10_REV_BIT
);
460 GET_CURRENT_CONTEXT(ctx
);
461 ASSERT_OUTSIDE_BEGIN_END(ctx
);
463 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
464 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
468 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
469 legalTypes
, 1, BGRA_OR_4
,
470 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
476 * GL_EXT_gpu_shader4 / GL 3.0.
477 * Set an integer-valued vertex attribute array.
478 * Note that these arrays DO NOT alias the conventional GL vertex arrays
479 * (position, normal, color, fog, texcoord, etc).
482 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
483 GLsizei stride
, const GLvoid
*ptr
)
485 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
486 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
487 INT_BIT
| UNSIGNED_INT_BIT
);
488 const GLboolean normalized
= GL_FALSE
;
489 const GLboolean integer
= GL_TRUE
;
490 GET_CURRENT_CONTEXT(ctx
);
491 ASSERT_OUTSIDE_BEGIN_END(ctx
);
493 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
494 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
498 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
500 size
, type
, stride
, normalized
, integer
, ptr
);
506 _mesa_EnableVertexAttribArrayARB(GLuint index
)
508 struct gl_array_object
*arrayObj
;
509 GET_CURRENT_CONTEXT(ctx
);
510 ASSERT_OUTSIDE_BEGIN_END(ctx
);
512 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
513 _mesa_error(ctx
, GL_INVALID_VALUE
,
514 "glEnableVertexAttribArrayARB(index)");
518 arrayObj
= ctx
->Array
.ArrayObj
;
520 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(arrayObj
->VertexAttrib
));
522 if (!arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
523 /* was disabled, now being enabled */
524 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
525 arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
526 arrayObj
->_Enabled
|= VERT_BIT_GENERIC(index
);
527 arrayObj
->NewArrays
|= VERT_BIT_GENERIC(index
);
533 _mesa_DisableVertexAttribArrayARB(GLuint index
)
535 struct gl_array_object
*arrayObj
;
536 GET_CURRENT_CONTEXT(ctx
);
537 ASSERT_OUTSIDE_BEGIN_END(ctx
);
539 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
540 _mesa_error(ctx
, GL_INVALID_VALUE
,
541 "glDisableVertexAttribArrayARB(index)");
545 arrayObj
= ctx
->Array
.ArrayObj
;
547 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(arrayObj
->VertexAttrib
));
549 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
550 /* was enabled, now being disabled */
551 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
552 arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
553 arrayObj
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
554 arrayObj
->NewArrays
|= VERT_BIT_GENERIC(index
);
560 * Return info for a vertex attribute array (no alias with legacy
561 * vertex attributes (pos, normal, color, etc)). This function does
562 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
565 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
568 const struct gl_client_array
*array
;
570 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
571 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
575 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
577 array
= &ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
580 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
581 return array
->Enabled
;
582 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
584 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
585 return array
->Stride
;
586 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
588 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
589 return array
->Normalized
;
590 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
591 return array
->BufferObj
->Name
;
592 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
593 if ((_mesa_is_desktop_gl(ctx
)
594 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
595 || _mesa_is_gles3(ctx
)) {
596 return array
->Integer
;
599 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
600 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
601 || _mesa_is_gles3(ctx
)) {
602 return array
->InstanceDivisor
;
610 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
615 static const GLfloat
*
616 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
619 /* In OpenGL 3.1 attribute 0 becomes non-magic, just like in OpenGL ES
620 * 2.0. Note that we cannot just check for API_OPENGL_CORE here because
621 * that will erroneously allow this usage in a 3.0 forward-compatible
624 if ((ctx
->API
!= API_OPENGL_CORE
|| ctx
->Version
< 31)
625 && ctx
->API
!= API_OPENGLES2
) {
626 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
630 else if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
631 _mesa_error(ctx
, GL_INVALID_VALUE
,
632 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
636 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
638 FLUSH_CURRENT(ctx
, 0);
639 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
643 _mesa_GetVertexAttribfvARB(GLuint index
, GLenum pname
, GLfloat
*params
)
645 GET_CURRENT_CONTEXT(ctx
);
646 ASSERT_OUTSIDE_BEGIN_END(ctx
);
648 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
649 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
655 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
656 "glGetVertexAttribfv");
662 _mesa_GetVertexAttribdvARB(GLuint index
, GLenum pname
, GLdouble
*params
)
664 GET_CURRENT_CONTEXT(ctx
);
665 ASSERT_OUTSIDE_BEGIN_END(ctx
);
667 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
668 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
670 params
[0] = (GLdouble
) v
[0];
671 params
[1] = (GLdouble
) v
[1];
672 params
[2] = (GLdouble
) v
[2];
673 params
[3] = (GLdouble
) v
[3];
677 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
678 "glGetVertexAttribdv");
684 _mesa_GetVertexAttribivARB(GLuint index
, GLenum pname
, GLint
*params
)
686 GET_CURRENT_CONTEXT(ctx
);
687 ASSERT_OUTSIDE_BEGIN_END(ctx
);
689 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
690 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
692 /* XXX should floats in[0,1] be scaled to full int range? */
693 params
[0] = (GLint
) v
[0];
694 params
[1] = (GLint
) v
[1];
695 params
[2] = (GLint
) v
[2];
696 params
[3] = (GLint
) v
[3];
700 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
701 "glGetVertexAttribiv");
708 _mesa_GetVertexAttribIiv(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
) {
715 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
717 /* XXX we don't have true integer-valued vertex attribs yet */
718 params
[0] = (GLint
) v
[0];
719 params
[1] = (GLint
) v
[1];
720 params
[2] = (GLint
) v
[2];
721 params
[3] = (GLint
) v
[3];
725 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
726 "glGetVertexAttribIiv");
733 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
735 GET_CURRENT_CONTEXT(ctx
);
736 ASSERT_OUTSIDE_BEGIN_END(ctx
);
738 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
740 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
742 /* XXX we don't have true integer-valued vertex attribs yet */
743 params
[0] = (GLuint
) v
[0];
744 params
[1] = (GLuint
) v
[1];
745 params
[2] = (GLuint
) v
[2];
746 params
[3] = (GLuint
) v
[3];
750 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
751 "glGetVertexAttribIuiv");
757 _mesa_GetVertexAttribPointervARB(GLuint index
, GLenum pname
, GLvoid
**pointer
)
759 GET_CURRENT_CONTEXT(ctx
);
760 ASSERT_OUTSIDE_BEGIN_END(ctx
);
762 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
763 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
767 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
768 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
772 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
774 *pointer
= (GLvoid
*) ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
779 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
780 GLsizei count
, const GLvoid
*ptr
)
783 _mesa_VertexPointer(size
, type
, stride
, ptr
);
788 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
792 _mesa_NormalPointer(type
, stride
, ptr
);
797 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
801 _mesa_ColorPointer(size
, type
, stride
, ptr
);
806 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
810 _mesa_IndexPointer(type
, stride
, ptr
);
815 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
816 GLsizei count
, const GLvoid
*ptr
)
819 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
824 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
827 _mesa_EdgeFlagPointer(stride
, ptr
);
832 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
834 GET_CURRENT_CONTEXT(ctx
);
835 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
836 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
837 GLenum ctype
= 0; /* color type */
838 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
839 const GLint toffset
= 0; /* always zero */
840 GLint defstride
; /* default stride */
843 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
846 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
849 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
855 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
856 tcomps
= 0; ccomps
= 0; vcomps
= 2;
861 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
862 tcomps
= 0; ccomps
= 0; vcomps
= 3;
867 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
868 tcomps
= 0; ccomps
= 4; vcomps
= 2;
869 ctype
= GL_UNSIGNED_BYTE
;
875 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
876 tcomps
= 0; ccomps
= 4; vcomps
= 3;
877 ctype
= GL_UNSIGNED_BYTE
;
883 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
884 tcomps
= 0; ccomps
= 3; vcomps
= 3;
891 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
892 tcomps
= 0; ccomps
= 0; vcomps
= 3;
898 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
899 tcomps
= 0; ccomps
= 4; vcomps
= 3;
907 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
908 tcomps
= 2; ccomps
= 0; vcomps
= 3;
913 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
914 tcomps
= 4; ccomps
= 0; vcomps
= 4;
918 case GL_T2F_C4UB_V3F
:
919 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
920 tcomps
= 2; ccomps
= 4; vcomps
= 3;
921 ctype
= GL_UNSIGNED_BYTE
;
927 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
928 tcomps
= 2; ccomps
= 3; vcomps
= 3;
935 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
936 tcomps
= 2; ccomps
= 0; vcomps
= 3;
941 case GL_T2F_C4F_N3F_V3F
:
942 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
943 tcomps
= 2; ccomps
= 4; vcomps
= 3;
950 case GL_T4F_C4F_N3F_V4F
:
951 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
952 tcomps
= 4; ccomps
= 4; vcomps
= 4;
960 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
968 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
969 _mesa_DisableClientState( GL_INDEX_ARRAY
);
970 /* XXX also disable secondary color and generic arrays? */
974 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
975 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
976 (GLubyte
*) pointer
+ toffset
);
979 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
984 _mesa_EnableClientState( GL_COLOR_ARRAY
);
985 _mesa_ColorPointer( ccomps
, ctype
, stride
,
986 (GLubyte
*) pointer
+ coffset
);
989 _mesa_DisableClientState( GL_COLOR_ARRAY
);
995 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
996 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
999 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1003 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1004 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1005 (GLubyte
*) pointer
+ voffset
);
1010 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1012 GET_CURRENT_CONTEXT(ctx
);
1013 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1015 if (MESA_VERBOSE
& VERBOSE_API
)
1016 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1019 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1023 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1026 if (ctx
->Array
.LockCount
!= 0) {
1027 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1031 ctx
->Array
.LockFirst
= first
;
1032 ctx
->Array
.LockCount
= count
;
1034 ctx
->NewState
|= _NEW_ARRAY
;
1039 _mesa_UnlockArraysEXT( void )
1041 GET_CURRENT_CONTEXT(ctx
);
1042 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1044 if (MESA_VERBOSE
& VERBOSE_API
)
1045 _mesa_debug(ctx
, "glUnlockArrays\n");
1047 if (ctx
->Array
.LockCount
== 0) {
1048 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1052 ctx
->Array
.LockFirst
= 0;
1053 ctx
->Array
.LockCount
= 0;
1054 ctx
->NewState
|= _NEW_ARRAY
;
1058 /* GL_EXT_multi_draw_arrays */
1060 _mesa_MultiDrawArraysEXT( GLenum mode
, const GLint
*first
,
1061 const GLsizei
*count
, GLsizei primcount
)
1063 GET_CURRENT_CONTEXT(ctx
);
1066 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1068 for (i
= 0; i
< primcount
; i
++) {
1070 CALL_DrawArrays(ctx
->Exec
, (mode
, first
[i
], count
[i
]));
1076 /* GL_IBM_multimode_draw_arrays */
1078 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1079 const GLsizei
* count
,
1080 GLsizei primcount
, GLint modestride
)
1082 GET_CURRENT_CONTEXT(ctx
);
1085 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1087 for ( i
= 0 ; i
< primcount
; i
++ ) {
1088 if ( count
[i
] > 0 ) {
1089 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1090 CALL_DrawArrays(ctx
->Exec
, ( m
, first
[i
], count
[i
] ));
1096 /* GL_IBM_multimode_draw_arrays */
1098 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1099 GLenum type
, const GLvoid
* const * indices
,
1100 GLsizei primcount
, GLint modestride
)
1102 GET_CURRENT_CONTEXT(ctx
);
1105 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1107 /* XXX not sure about ARB_vertex_buffer_object handling here */
1109 for ( i
= 0 ; i
< primcount
; i
++ ) {
1110 if ( count
[i
] > 0 ) {
1111 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1112 CALL_DrawElements(ctx
->Exec
, ( m
, count
[i
], type
, indices
[i
] ));
1119 * GL_NV_primitive_restart and GL 3.1
1122 _mesa_PrimitiveRestartIndex(GLuint index
)
1124 GET_CURRENT_CONTEXT(ctx
);
1126 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1127 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1131 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1133 if (ctx
->Array
.RestartIndex
!= index
) {
1134 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1135 ctx
->Array
.RestartIndex
= index
;
1141 * See GL_ARB_instanced_arrays.
1142 * Note that the instance divisor only applies to generic arrays, not
1143 * the legacy vertex arrays.
1146 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1148 struct gl_client_array
*array
;
1149 GET_CURRENT_CONTEXT(ctx
);
1150 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1152 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1153 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1157 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
1158 _mesa_error(ctx
, GL_INVALID_ENUM
, "glVertexAttribDivisor(index = %u)",
1163 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
1165 array
= &ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
1166 if (array
->InstanceDivisor
!= divisor
) {
1167 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
1168 array
->InstanceDivisor
= divisor
;
1169 ctx
->Array
.ArrayObj
->NewArrays
|= VERT_BIT(VERT_ATTRIB_GENERIC(index
));
1176 * Copy one client vertex array to another.
1179 _mesa_copy_client_array(struct gl_context
*ctx
,
1180 struct gl_client_array
*dst
,
1181 struct gl_client_array
*src
)
1183 dst
->Size
= src
->Size
;
1184 dst
->Type
= src
->Type
;
1185 dst
->Format
= src
->Format
;
1186 dst
->Stride
= src
->Stride
;
1187 dst
->StrideB
= src
->StrideB
;
1188 dst
->Ptr
= src
->Ptr
;
1189 dst
->Enabled
= src
->Enabled
;
1190 dst
->Normalized
= src
->Normalized
;
1191 dst
->Integer
= src
->Integer
;
1192 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1193 dst
->_ElementSize
= src
->_ElementSize
;
1194 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1195 dst
->_MaxElement
= src
->_MaxElement
;
1201 * Print vertex array's fields.
1204 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1207 printf(" %s[%d]: ", name
, index
);
1209 printf(" %s: ", name
);
1210 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
1211 array
->Ptr
, array
->Type
, array
->Size
,
1212 array
->_ElementSize
, array
->StrideB
,
1213 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
,
1214 array
->_MaxElement
);
1219 * Print current vertex object/array info. For debug.
1222 _mesa_print_arrays(struct gl_context
*ctx
)
1224 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
1227 _mesa_update_array_object_max_element(ctx
, arrayObj
);
1229 printf("Array Object %u\n", arrayObj
->Name
);
1230 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
1231 print_array("Vertex", -1, &arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
]);
1232 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
1233 print_array("Normal", -1, &arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
]);
1234 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
1235 print_array("Color", -1, &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
]);
1236 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
1237 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
1238 print_array("TexCoord", i
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
1239 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
1240 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
1241 print_array("Attrib", i
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
1242 printf(" _MaxElement = %u\n", arrayObj
->_MaxElement
);
1247 * Initialize vertex array state for given context.
1250 _mesa_init_varray(struct gl_context
*ctx
)
1252 ctx
->Array
.DefaultArrayObj
= ctx
->Driver
.NewArrayObject(ctx
, 0);
1253 _mesa_reference_array_object(ctx
, &ctx
->Array
.ArrayObj
,
1254 ctx
->Array
.DefaultArrayObj
);
1255 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1257 ctx
->Array
.Objects
= _mesa_NewHashTable();
1262 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1265 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1267 struct gl_array_object
*arrayObj
= (struct gl_array_object
*) data
;
1268 struct gl_context
*ctx
= (struct gl_context
*) userData
;
1269 _mesa_delete_array_object(ctx
, arrayObj
);
1274 * Free vertex array state for given context.
1277 _mesa_free_varray_data(struct gl_context
*ctx
)
1279 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1280 _mesa_DeleteHashTable(ctx
->Array
.Objects
);