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"
37 #include "glapi/dispatch.h"
41 * Set the fields of a vertex array.
42 * Also do an error check for GL_ARB_vertex_array_object: check that
43 * all arrays reside in VBOs when using a vertex array object.
45 * \param array the array to update
46 * \param dirtyBit which bit to set in ctx->Array.NewState for this array
47 * \param elementSize size of each array element, in bytes
48 * \param size components per element (1, 2, 3 or 4)
49 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
50 * \param format either GL_RGBA or GL_BGRA
51 * \param stride stride between elements, in elements
52 * \param normalized are integer types converted to floats in [-1, 1]?
53 * \param ptr the address (or offset inside VBO) of the array data
54 * \return GL_TRUE if no error, GL_FALSE if error
57 update_array(GLcontext
*ctx
, struct gl_client_array
*array
,
58 GLbitfield dirtyBit
, GLsizei elementSize
,
59 GLint size
, GLenum type
, GLenum format
,
60 GLsizei stride
, GLboolean normalized
, const GLvoid
*ptr
)
62 ASSERT(format
== GL_RGBA
|| format
== GL_BGRA
);
64 if (ctx
->Array
.ArrayObj
->VBOonly
&&
65 ctx
->Array
.ArrayBufferObj
->Name
== 0) {
66 /* GL_ARB_vertex_array_object requires that all arrays reside in VBOs.
67 * Generate GL_INVALID_OPERATION if that's not true.
69 _mesa_error(ctx
, GL_INVALID_OPERATION
,
70 "glVertex/Normal/EtcPointer(non-VBO array)");
76 array
->Format
= format
;
77 array
->Stride
= stride
;
78 array
->StrideB
= stride
? stride
: elementSize
;
79 array
->Normalized
= normalized
;
80 array
->Ptr
= (const GLubyte
*) ptr
;
81 array
->_ElementSize
= elementSize
;
83 _mesa_reference_buffer_object(ctx
, &array
->BufferObj
,
84 ctx
->Array
.ArrayBufferObj
);
86 ctx
->NewState
|= _NEW_ARRAY
;
87 ctx
->Array
.NewState
|= dirtyBit
;
94 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
97 GET_CURRENT_CONTEXT(ctx
);
98 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
100 if (size
< 2 || size
> 4) {
101 _mesa_error( ctx
, GL_INVALID_VALUE
, "glVertexPointer(size)" );
105 _mesa_error( ctx
, GL_INVALID_VALUE
, "glVertexPointer(stride)" );
109 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
110 _mesa_debug(ctx
, "glVertexPointer( sz %d type %s stride %d )\n", size
,
111 _mesa_lookup_enum_by_nr( type
), stride
);
113 /* always need to check that <type> is legal */
116 elementSize
= size
* sizeof(GLshort
);
119 elementSize
= size
* sizeof(GLint
);
122 elementSize
= size
* sizeof(GLfloat
);
125 elementSize
= size
* sizeof(GLdouble
);
129 elementSize
= size
* sizeof(GLfixed
);
132 #if FEATURE_vertex_array_byte
134 elementSize
= size
* sizeof(GLbyte
);
138 _mesa_error( ctx
, GL_INVALID_ENUM
, "glVertexPointer(type)" );
142 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->Vertex
, _NEW_ARRAY_VERTEX
,
143 elementSize
, size
, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
))
146 if (ctx
->Driver
.VertexPointer
)
147 ctx
->Driver
.VertexPointer( ctx
, size
, type
, stride
, ptr
);
152 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
155 GET_CURRENT_CONTEXT(ctx
);
156 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
159 _mesa_error( ctx
, GL_INVALID_VALUE
, "glNormalPointer(stride)" );
163 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
164 _mesa_debug(ctx
, "glNormalPointer( type %s stride %d )\n",
165 _mesa_lookup_enum_by_nr( type
), stride
);
169 elementSize
= 3 * sizeof(GLbyte
);
172 elementSize
= 3 * sizeof(GLshort
);
175 elementSize
= 3 * sizeof(GLint
);
178 elementSize
= 3 * sizeof(GLfloat
);
181 elementSize
= 3 * sizeof(GLdouble
);
185 elementSize
= 3 * sizeof(GLfixed
);
189 _mesa_error( ctx
, GL_INVALID_ENUM
, "glNormalPointer(type)" );
193 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->Normal
, _NEW_ARRAY_NORMAL
,
194 elementSize
, 3, type
, GL_RGBA
, stride
, GL_TRUE
, ptr
))
197 if (ctx
->Driver
.NormalPointer
)
198 ctx
->Driver
.NormalPointer( ctx
, type
, stride
, ptr
);
203 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
207 GET_CURRENT_CONTEXT(ctx
);
208 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
210 if (size
< 3 || size
> 4) {
211 if (!ctx
->Extensions
.EXT_vertex_array_bgra
|| size
!= GL_BGRA
) {
212 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorPointer(size)");
217 _mesa_error( ctx
, GL_INVALID_VALUE
, "glColorPointer(stride)" );
221 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
222 _mesa_debug(ctx
, "glColorPointer( sz %d type %s stride %d )\n", size
,
223 _mesa_lookup_enum_by_nr( type
), stride
);
225 if (size
== GL_BGRA
) {
226 if (type
!= GL_UNSIGNED_BYTE
) {
227 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorPointer(GL_BGRA/GLubyte)");
239 elementSize
= size
* sizeof(GLbyte
);
241 case GL_UNSIGNED_BYTE
:
242 elementSize
= size
* sizeof(GLubyte
);
245 elementSize
= size
* sizeof(GLshort
);
247 case GL_UNSIGNED_SHORT
:
248 elementSize
= size
* sizeof(GLushort
);
251 elementSize
= size
* sizeof(GLint
);
253 case GL_UNSIGNED_INT
:
254 elementSize
= size
* sizeof(GLuint
);
257 elementSize
= size
* sizeof(GLfloat
);
260 elementSize
= size
* sizeof(GLdouble
);
264 elementSize
= size
* sizeof(GLfixed
);
268 _mesa_error( ctx
, GL_INVALID_ENUM
, "glColorPointer(type)" );
272 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->Color
, _NEW_ARRAY_COLOR0
,
273 elementSize
, size
, type
, format
, stride
, GL_TRUE
, ptr
))
276 if (ctx
->Driver
.ColorPointer
)
277 ctx
->Driver
.ColorPointer( ctx
, size
, type
, stride
, ptr
);
282 _mesa_FogCoordPointerEXT(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
285 GET_CURRENT_CONTEXT(ctx
);
286 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
289 _mesa_error( ctx
, GL_INVALID_VALUE
, "glFogCoordPointer(stride)" );
295 elementSize
= sizeof(GLfloat
);
298 elementSize
= sizeof(GLdouble
);
301 _mesa_error( ctx
, GL_INVALID_ENUM
, "glFogCoordPointer(type)" );
305 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->FogCoord
, _NEW_ARRAY_FOGCOORD
,
306 elementSize
, 1, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
))
309 if (ctx
->Driver
.FogCoordPointer
)
310 ctx
->Driver
.FogCoordPointer( ctx
, type
, stride
, ptr
);
315 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
318 GET_CURRENT_CONTEXT(ctx
);
319 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
322 _mesa_error( ctx
, GL_INVALID_VALUE
, "glIndexPointer(stride)" );
327 case GL_UNSIGNED_BYTE
:
328 elementSize
= sizeof(GLubyte
);
331 elementSize
= sizeof(GLshort
);
334 elementSize
= sizeof(GLint
);
337 elementSize
= sizeof(GLfloat
);
340 elementSize
= sizeof(GLdouble
);
343 _mesa_error( ctx
, GL_INVALID_ENUM
, "glIndexPointer(type)" );
347 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->Index
, _NEW_ARRAY_INDEX
,
348 elementSize
, 1, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
))
351 if (ctx
->Driver
.IndexPointer
)
352 ctx
->Driver
.IndexPointer( ctx
, type
, stride
, ptr
);
357 _mesa_SecondaryColorPointerEXT(GLint size
, GLenum type
,
358 GLsizei stride
, const GLvoid
*ptr
)
362 GET_CURRENT_CONTEXT(ctx
);
363 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
365 if (size
!= 3 && size
!= 4) {
366 if (!ctx
->Extensions
.EXT_vertex_array_bgra
|| size
!= GL_BGRA
) {
367 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSecondaryColorPointer(size)");
372 _mesa_error( ctx
, GL_INVALID_VALUE
, "glSecondaryColorPointer(stride)" );
376 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
377 _mesa_debug(ctx
, "glSecondaryColorPointer( sz %d type %s stride %d )\n",
378 size
, _mesa_lookup_enum_by_nr( type
), stride
);
380 if (size
== GL_BGRA
) {
381 if (type
!= GL_UNSIGNED_BYTE
) {
382 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorPointer(GL_BGRA/GLubyte)");
394 elementSize
= size
* sizeof(GLbyte
);
396 case GL_UNSIGNED_BYTE
:
397 elementSize
= size
* sizeof(GLubyte
);
400 elementSize
= size
* sizeof(GLshort
);
402 case GL_UNSIGNED_SHORT
:
403 elementSize
= size
* sizeof(GLushort
);
406 elementSize
= size
* sizeof(GLint
);
408 case GL_UNSIGNED_INT
:
409 elementSize
= size
* sizeof(GLuint
);
412 elementSize
= size
* sizeof(GLfloat
);
415 elementSize
= size
* sizeof(GLdouble
);
418 _mesa_error( ctx
, GL_INVALID_ENUM
, "glSecondaryColorPointer(type)" );
422 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->SecondaryColor
,
423 _NEW_ARRAY_COLOR1
, elementSize
, size
, type
,
424 format
, stride
, GL_TRUE
, ptr
))
427 if (ctx
->Driver
.SecondaryColorPointer
)
428 ctx
->Driver
.SecondaryColorPointer( ctx
, size
, type
, stride
, ptr
);
433 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
437 GET_CURRENT_CONTEXT(ctx
);
438 const GLuint unit
= ctx
->Array
.ActiveTexture
;
439 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
441 if (size
< 1 || size
> 4) {
442 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexCoordPointer(size)" );
446 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexCoordPointer(stride)" );
450 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
451 _mesa_debug(ctx
, "glTexCoordPointer(unit %u sz %d type %s stride %d)\n",
452 unit
, size
, _mesa_lookup_enum_by_nr( type
), stride
);
454 /* always need to check that <type> is legal */
457 elementSize
= size
* sizeof(GLshort
);
460 elementSize
= size
* sizeof(GLint
);
463 elementSize
= size
* sizeof(GLfloat
);
466 elementSize
= size
* sizeof(GLdouble
);
470 elementSize
= size
* sizeof(GLfixed
);
473 #if FEATURE_vertex_array_byte
475 elementSize
= size
* sizeof(GLbyte
);
479 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexCoordPointer(type)" );
483 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->TexCoord
[unit
],
484 _NEW_ARRAY_TEXCOORD(unit
),
485 elementSize
, size
, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
))
488 if (ctx
->Driver
.TexCoordPointer
)
489 ctx
->Driver
.TexCoordPointer( ctx
, size
, type
, stride
, ptr
);
494 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
496 GET_CURRENT_CONTEXT(ctx
);
497 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
500 _mesa_error( ctx
, GL_INVALID_VALUE
, "glEdgeFlagPointer(stride)" );
504 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->EdgeFlag
, _NEW_ARRAY_EDGEFLAG
,
505 sizeof(GLboolean
), 1, GL_UNSIGNED_BYTE
, GL_RGBA
,
506 stride
, GL_FALSE
, ptr
))
509 if (ctx
->Driver
.EdgeFlagPointer
)
510 ctx
->Driver
.EdgeFlagPointer( ctx
, stride
, ptr
);
515 _mesa_PointSizePointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
518 GET_CURRENT_CONTEXT(ctx
);
519 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
522 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPointSizePointer(stride)" );
528 elementSize
= sizeof(GLfloat
);
532 elementSize
= sizeof(GLfixed
);
536 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPointSizePointer(type)" );
540 update_array(ctx
, &ctx
->Array
.ArrayObj
->PointSize
, _NEW_ARRAY_POINT_SIZE
,
541 elementSize
, 1, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
);
545 #if FEATURE_NV_vertex_program
547 * Set a vertex attribute array.
548 * Note that these arrays DO alias the conventional GL vertex arrays
549 * (position, normal, color, fog, texcoord, etc).
550 * The generic attribute slots at #16 and above are not touched.
553 _mesa_VertexAttribPointerNV(GLuint index
, GLint size
, GLenum type
,
554 GLsizei stride
, const GLvoid
*ptr
)
556 GLboolean normalized
= GL_FALSE
;
559 GET_CURRENT_CONTEXT(ctx
);
560 ASSERT_OUTSIDE_BEGIN_END(ctx
);
562 if (index
>= MAX_NV_VERTEX_PROGRAM_INPUTS
) {
563 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(index)");
567 if (size
< 1 || size
> 4) {
568 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(size)");
573 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(stride)");
577 if (type
== GL_UNSIGNED_BYTE
&& size
!= 4) {
578 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(size!=4)");
582 if (size
== GL_BGRA
) {
583 if (type
!= GL_UNSIGNED_BYTE
) {
584 _mesa_error(ctx
, GL_INVALID_VALUE
,
585 "glVertexAttribPointerNV(GL_BGRA/type)");
591 normalized
= GL_TRUE
;
597 /* check for valid 'type' and compute StrideB right away */
599 case GL_UNSIGNED_BYTE
:
600 normalized
= GL_TRUE
;
601 elementSize
= size
* sizeof(GLubyte
);
604 elementSize
= size
* sizeof(GLshort
);
607 elementSize
= size
* sizeof(GLfloat
);
610 elementSize
= size
* sizeof(GLdouble
);
613 _mesa_error( ctx
, GL_INVALID_ENUM
, "glVertexAttribPointerNV(type)" );
617 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
618 _NEW_ARRAY_ATTRIB(index
),
619 elementSize
, size
, type
, format
, stride
, normalized
, ptr
))
622 if (ctx
->Driver
.VertexAttribPointer
)
623 ctx
->Driver
.VertexAttribPointer( ctx
, index
, size
, type
, stride
, ptr
);
628 #if FEATURE_ARB_vertex_program
630 * Set a generic vertex attribute array.
631 * Note that these arrays DO NOT alias the conventional GL vertex arrays
632 * (position, normal, color, fog, texcoord, etc).
635 _mesa_VertexAttribPointerARB(GLuint index
, GLint size
, GLenum type
,
636 GLboolean normalized
,
637 GLsizei stride
, const GLvoid
*ptr
)
641 GET_CURRENT_CONTEXT(ctx
);
642 ASSERT_OUTSIDE_BEGIN_END(ctx
);
644 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
645 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
649 if (size
< 1 || size
> 4) {
650 if (!ctx
->Extensions
.EXT_vertex_array_bgra
|| size
!= GL_BGRA
) {
651 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(size)");
657 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(stride)");
661 if (size
== GL_BGRA
) {
662 if (type
!= GL_UNSIGNED_BYTE
) {
663 _mesa_error(ctx
, GL_INVALID_VALUE
,
664 "glVertexAttribPointerARB(GL_BGRA/type)");
667 if (normalized
!= GL_TRUE
) {
668 _mesa_error(ctx
, GL_INVALID_VALUE
,
669 "glVertexAttribPointerARB(GL_BGRA/normalized)");
680 /* check for valid 'type' and compute StrideB right away */
681 /* NOTE: more types are supported here than in the NV extension */
684 elementSize
= size
* sizeof(GLbyte
);
686 case GL_UNSIGNED_BYTE
:
687 elementSize
= size
* sizeof(GLubyte
);
690 elementSize
= size
* sizeof(GLshort
);
692 case GL_UNSIGNED_SHORT
:
693 elementSize
= size
* sizeof(GLushort
);
696 elementSize
= size
* sizeof(GLint
);
698 case GL_UNSIGNED_INT
:
699 elementSize
= size
* sizeof(GLuint
);
702 elementSize
= size
* sizeof(GLfloat
);
705 elementSize
= size
* sizeof(GLdouble
);
709 elementSize
= size
* sizeof(GLfixed
);
713 _mesa_error( ctx
, GL_INVALID_ENUM
, "glVertexAttribPointerARB(type)" );
717 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
718 _NEW_ARRAY_ATTRIB(index
),
719 elementSize
, size
, type
, format
, stride
, normalized
, ptr
))
722 if (ctx
->Driver
.VertexAttribPointer
)
723 ctx
->Driver
.VertexAttribPointer(ctx
, index
, size
, type
, stride
, ptr
);
729 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
730 GLsizei count
, const GLvoid
*ptr
)
733 _mesa_VertexPointer(size
, type
, stride
, ptr
);
738 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
742 _mesa_NormalPointer(type
, stride
, ptr
);
747 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
751 _mesa_ColorPointer(size
, type
, stride
, ptr
);
756 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
760 _mesa_IndexPointer(type
, stride
, ptr
);
765 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
766 GLsizei count
, const GLvoid
*ptr
)
769 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
774 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
777 _mesa_EdgeFlagPointer(stride
, ptr
);
782 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
784 GET_CURRENT_CONTEXT(ctx
);
785 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
786 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
787 GLenum ctype
= 0; /* color type */
788 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
789 const GLint toffset
= 0; /* always zero */
790 GLint defstride
; /* default stride */
793 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
796 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
799 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
805 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
806 tcomps
= 0; ccomps
= 0; vcomps
= 2;
811 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
812 tcomps
= 0; ccomps
= 0; vcomps
= 3;
817 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
818 tcomps
= 0; ccomps
= 4; vcomps
= 2;
819 ctype
= GL_UNSIGNED_BYTE
;
825 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
826 tcomps
= 0; ccomps
= 4; vcomps
= 3;
827 ctype
= GL_UNSIGNED_BYTE
;
833 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
834 tcomps
= 0; ccomps
= 3; vcomps
= 3;
841 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
842 tcomps
= 0; ccomps
= 0; vcomps
= 3;
848 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
849 tcomps
= 0; ccomps
= 4; vcomps
= 3;
857 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
858 tcomps
= 2; ccomps
= 0; vcomps
= 3;
863 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
864 tcomps
= 4; ccomps
= 0; vcomps
= 4;
868 case GL_T2F_C4UB_V3F
:
869 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
870 tcomps
= 2; ccomps
= 4; vcomps
= 3;
871 ctype
= GL_UNSIGNED_BYTE
;
877 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
878 tcomps
= 2; ccomps
= 3; vcomps
= 3;
885 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
886 tcomps
= 2; ccomps
= 0; vcomps
= 3;
891 case GL_T2F_C4F_N3F_V3F
:
892 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
893 tcomps
= 2; ccomps
= 4; vcomps
= 3;
900 case GL_T4F_C4F_N3F_V4F
:
901 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
902 tcomps
= 4; ccomps
= 4; vcomps
= 4;
910 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
918 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
919 _mesa_DisableClientState( GL_INDEX_ARRAY
);
920 /* XXX also disable secondary color and generic arrays? */
924 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
925 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
926 (GLubyte
*) pointer
+ toffset
);
929 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
934 _mesa_EnableClientState( GL_COLOR_ARRAY
);
935 _mesa_ColorPointer( ccomps
, ctype
, stride
,
936 (GLubyte
*) pointer
+ coffset
);
939 _mesa_DisableClientState( GL_COLOR_ARRAY
);
945 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
946 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
949 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
953 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
954 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
955 (GLubyte
*) pointer
+ voffset
);
960 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
962 GET_CURRENT_CONTEXT(ctx
);
963 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
965 if (MESA_VERBOSE
& VERBOSE_API
)
966 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
969 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
973 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
976 if (ctx
->Array
.LockCount
!= 0) {
977 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
981 ctx
->Array
.LockFirst
= first
;
982 ctx
->Array
.LockCount
= count
;
984 ctx
->NewState
|= _NEW_ARRAY
;
985 ctx
->Array
.NewState
|= _NEW_ARRAY_ALL
;
987 if (ctx
->Driver
.LockArraysEXT
)
988 ctx
->Driver
.LockArraysEXT( ctx
, first
, count
);
993 _mesa_UnlockArraysEXT( void )
995 GET_CURRENT_CONTEXT(ctx
);
996 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
998 if (MESA_VERBOSE
& VERBOSE_API
)
999 _mesa_debug(ctx
, "glUnlockArrays\n");
1001 if (ctx
->Array
.LockCount
== 0) {
1002 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1006 ctx
->Array
.LockFirst
= 0;
1007 ctx
->Array
.LockCount
= 0;
1008 ctx
->NewState
|= _NEW_ARRAY
;
1009 ctx
->Array
.NewState
|= _NEW_ARRAY_ALL
;
1011 if (ctx
->Driver
.UnlockArraysEXT
)
1012 ctx
->Driver
.UnlockArraysEXT( ctx
);
1016 /* GL_EXT_multi_draw_arrays */
1017 /* Somebody forgot to spec the first and count parameters as const! <sigh> */
1019 _mesa_MultiDrawArraysEXT( GLenum mode
, GLint
*first
,
1020 GLsizei
*count
, GLsizei primcount
)
1022 GET_CURRENT_CONTEXT(ctx
);
1025 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1027 for (i
= 0; i
< primcount
; i
++) {
1029 CALL_DrawArrays(ctx
->Exec
, (mode
, first
[i
], count
[i
]));
1035 /* GL_EXT_multi_draw_arrays */
1037 _mesa_MultiDrawElementsEXT( GLenum mode
, const GLsizei
*count
, GLenum type
,
1038 const GLvoid
**indices
, GLsizei primcount
)
1040 GET_CURRENT_CONTEXT(ctx
);
1043 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1045 for (i
= 0; i
< primcount
; i
++) {
1047 CALL_DrawElements(ctx
->Exec
, (mode
, count
[i
], type
, indices
[i
]));
1053 /* GL_IBM_multimode_draw_arrays */
1055 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1056 const GLsizei
* count
,
1057 GLsizei primcount
, GLint modestride
)
1059 GET_CURRENT_CONTEXT(ctx
);
1062 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1064 for ( i
= 0 ; i
< primcount
; i
++ ) {
1065 if ( count
[i
] > 0 ) {
1066 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1067 CALL_DrawArrays(ctx
->Exec
, ( m
, first
[i
], count
[i
] ));
1073 /* GL_IBM_multimode_draw_arrays */
1075 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1076 GLenum type
, const GLvoid
* const * indices
,
1077 GLsizei primcount
, GLint modestride
)
1079 GET_CURRENT_CONTEXT(ctx
);
1082 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1084 /* XXX not sure about ARB_vertex_buffer_object handling here */
1086 for ( i
= 0 ; i
< primcount
; i
++ ) {
1087 if ( count
[i
] > 0 ) {
1088 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1089 CALL_DrawElements(ctx
->Exec
, ( m
, count
[i
], type
, indices
[i
] ));
1096 * Print vertex array's fields.
1099 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1102 _mesa_printf(" %s[%d]: ", name
, index
);
1104 _mesa_printf(" %s: ", name
);
1105 _mesa_printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %u), MaxElem=%u\n",
1106 array
->Ptr
, array
->Type
, array
->Size
,
1107 array
->_ElementSize
, array
->StrideB
,
1108 array
->BufferObj
->Name
, array
->BufferObj
->Size
,
1109 array
->_MaxElement
);
1114 * Print current vertex object/array info. For debug.
1117 _mesa_print_arrays(GLcontext
*ctx
)
1119 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
1122 _mesa_update_array_object_max_element(ctx
, arrayObj
);
1124 _mesa_printf("Array Object %u\n", arrayObj
->Name
);
1125 if (arrayObj
->Vertex
.Enabled
)
1126 print_array("Vertex", -1, &arrayObj
->Vertex
);
1127 if (arrayObj
->Normal
.Enabled
)
1128 print_array("Normal", -1, &arrayObj
->Normal
);
1129 if (arrayObj
->Color
.Enabled
)
1130 print_array("Color", -1, &arrayObj
->Color
);
1131 for (i
= 0; i
< Elements(arrayObj
->TexCoord
); i
++)
1132 if (arrayObj
->TexCoord
[i
].Enabled
)
1133 print_array("TexCoord", i
, &arrayObj
->TexCoord
[i
]);
1134 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++)
1135 if (arrayObj
->VertexAttrib
[i
].Enabled
)
1136 print_array("Attrib", i
, &arrayObj
->VertexAttrib
[i
]);
1137 _mesa_printf(" _MaxElement = %u\n", arrayObj
->_MaxElement
);
1142 * Initialize vertex array state for given context.
1145 _mesa_init_varray(GLcontext
*ctx
)
1147 ctx
->Array
.DefaultArrayObj
= _mesa_new_array_object(ctx
, 0);
1148 _mesa_reference_array_object(ctx
, &ctx
->Array
.ArrayObj
,
1149 ctx
->Array
.DefaultArrayObj
);
1150 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1152 ctx
->Array
.Objects
= _mesa_NewHashTable();
1157 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1160 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1162 struct gl_array_object
*arrayObj
= (struct gl_array_object
*) data
;
1163 GLcontext
*ctx
= (GLcontext
*) userData
;
1164 _mesa_delete_array_object(ctx
, arrayObj
);
1169 * Free vertex array state for given context.
1172 _mesa_free_varray_data(GLcontext
*ctx
)
1174 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1175 _mesa_DeleteHashTable(ctx
->Array
.Objects
);