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 "glapi/dispatch.h"
40 * Set the fields of a vertex array.
42 * \param array the array to update
43 * \param dirtyBit which bit to set in ctx->Array.NewState for this array
44 * \param elementSize size of each array element, in bytes
45 * \param size components per element (1, 2, 3 or 4)
46 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
47 * \param format either GL_RGBA or GL_BGRA
48 * \param stride stride between elements, in elements
49 * \param normalized are integer types converted to floats in [-1, 1]?
50 * \param ptr the address (or offset inside VBO) of the array data
53 update_array(GLcontext
*ctx
, struct gl_client_array
*array
,
54 GLbitfield dirtyBit
, GLsizei elementSize
,
55 GLint size
, GLenum type
, GLenum format
,
56 GLsizei stride
, GLboolean normalized
, const GLvoid
*ptr
)
58 ASSERT(format
== GL_RGBA
|| format
== GL_BGRA
);
61 array
->Format
= format
;
62 array
->Stride
= stride
;
63 array
->StrideB
= stride
? stride
: elementSize
;
64 array
->Normalized
= normalized
;
65 array
->Ptr
= (const GLubyte
*) ptr
;
66 array
->_ElementSize
= elementSize
;
68 _mesa_reference_buffer_object(ctx
, &array
->BufferObj
,
69 ctx
->Array
.ArrayBufferObj
);
71 ctx
->NewState
|= _NEW_ARRAY
;
72 ctx
->Array
.NewState
|= dirtyBit
;
77 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
80 GET_CURRENT_CONTEXT(ctx
);
81 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
83 if (size
< 2 || size
> 4) {
84 _mesa_error( ctx
, GL_INVALID_VALUE
, "glVertexPointer(size)" );
88 _mesa_error( ctx
, GL_INVALID_VALUE
, "glVertexPointer(stride)" );
92 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
93 _mesa_debug(ctx
, "glVertexPointer( sz %d type %s stride %d )\n", size
,
94 _mesa_lookup_enum_by_nr( type
), stride
);
96 /* always need to check that <type> is legal */
99 elementSize
= size
* sizeof(GLshort
);
102 elementSize
= size
* sizeof(GLint
);
105 elementSize
= size
* sizeof(GLfloat
);
108 elementSize
= size
* sizeof(GLdouble
);
112 elementSize
= size
* sizeof(GLfixed
);
115 #if FEATURE_vertex_array_byte
117 elementSize
= size
* sizeof(GLbyte
);
121 _mesa_error( ctx
, GL_INVALID_ENUM
, "glVertexPointer(type)" );
125 update_array(ctx
, &ctx
->Array
.ArrayObj
->Vertex
, _NEW_ARRAY_VERTEX
,
126 elementSize
, size
, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
);
128 if (ctx
->Driver
.VertexPointer
)
129 ctx
->Driver
.VertexPointer( ctx
, size
, type
, stride
, ptr
);
134 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
137 GET_CURRENT_CONTEXT(ctx
);
138 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
141 _mesa_error( ctx
, GL_INVALID_VALUE
, "glNormalPointer(stride)" );
145 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
146 _mesa_debug(ctx
, "glNormalPointer( type %s stride %d )\n",
147 _mesa_lookup_enum_by_nr( type
), stride
);
151 elementSize
= 3 * sizeof(GLbyte
);
154 elementSize
= 3 * sizeof(GLshort
);
157 elementSize
= 3 * sizeof(GLint
);
160 elementSize
= 3 * sizeof(GLfloat
);
163 elementSize
= 3 * sizeof(GLdouble
);
167 elementSize
= 3 * sizeof(GLfixed
);
171 _mesa_error( ctx
, GL_INVALID_ENUM
, "glNormalPointer(type)" );
175 update_array(ctx
, &ctx
->Array
.ArrayObj
->Normal
, _NEW_ARRAY_NORMAL
,
176 elementSize
, 3, type
, GL_RGBA
, stride
, GL_TRUE
, ptr
);
178 if (ctx
->Driver
.NormalPointer
)
179 ctx
->Driver
.NormalPointer( ctx
, type
, stride
, ptr
);
184 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
188 GET_CURRENT_CONTEXT(ctx
);
189 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
191 if (size
< 3 || size
> 4) {
192 if (!ctx
->Extensions
.EXT_vertex_array_bgra
|| size
!= GL_BGRA
) {
193 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorPointer(size)");
198 _mesa_error( ctx
, GL_INVALID_VALUE
, "glColorPointer(stride)" );
202 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
203 _mesa_debug(ctx
, "glColorPointer( sz %d type %s stride %d )\n", size
,
204 _mesa_lookup_enum_by_nr( type
), stride
);
206 if (size
== GL_BGRA
) {
207 if (type
!= GL_UNSIGNED_BYTE
) {
208 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorPointer(GL_BGRA/GLubyte)");
220 elementSize
= size
* sizeof(GLbyte
);
222 case GL_UNSIGNED_BYTE
:
223 elementSize
= size
* sizeof(GLubyte
);
226 elementSize
= size
* sizeof(GLshort
);
228 case GL_UNSIGNED_SHORT
:
229 elementSize
= size
* sizeof(GLushort
);
232 elementSize
= size
* sizeof(GLint
);
234 case GL_UNSIGNED_INT
:
235 elementSize
= size
* sizeof(GLuint
);
238 elementSize
= size
* sizeof(GLfloat
);
241 elementSize
= size
* sizeof(GLdouble
);
245 elementSize
= size
* sizeof(GLfixed
);
249 _mesa_error( ctx
, GL_INVALID_ENUM
, "glColorPointer(type)" );
253 update_array(ctx
, &ctx
->Array
.ArrayObj
->Color
, _NEW_ARRAY_COLOR0
,
254 elementSize
, size
, type
, format
, stride
, GL_TRUE
, ptr
);
256 if (ctx
->Driver
.ColorPointer
)
257 ctx
->Driver
.ColorPointer( ctx
, size
, type
, stride
, ptr
);
262 _mesa_FogCoordPointerEXT(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
265 GET_CURRENT_CONTEXT(ctx
);
266 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
269 _mesa_error( ctx
, GL_INVALID_VALUE
, "glFogCoordPointer(stride)" );
275 elementSize
= sizeof(GLfloat
);
278 elementSize
= sizeof(GLdouble
);
281 _mesa_error( ctx
, GL_INVALID_ENUM
, "glFogCoordPointer(type)" );
285 update_array(ctx
, &ctx
->Array
.ArrayObj
->FogCoord
, _NEW_ARRAY_FOGCOORD
,
286 elementSize
, 1, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
);
288 if (ctx
->Driver
.FogCoordPointer
)
289 ctx
->Driver
.FogCoordPointer( ctx
, type
, stride
, ptr
);
294 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
297 GET_CURRENT_CONTEXT(ctx
);
298 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
301 _mesa_error( ctx
, GL_INVALID_VALUE
, "glIndexPointer(stride)" );
306 case GL_UNSIGNED_BYTE
:
307 elementSize
= sizeof(GLubyte
);
310 elementSize
= sizeof(GLshort
);
313 elementSize
= sizeof(GLint
);
316 elementSize
= sizeof(GLfloat
);
319 elementSize
= sizeof(GLdouble
);
322 _mesa_error( ctx
, GL_INVALID_ENUM
, "glIndexPointer(type)" );
326 update_array(ctx
, &ctx
->Array
.ArrayObj
->Index
, _NEW_ARRAY_INDEX
,
327 elementSize
, 1, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
);
329 if (ctx
->Driver
.IndexPointer
)
330 ctx
->Driver
.IndexPointer( ctx
, type
, stride
, ptr
);
335 _mesa_SecondaryColorPointerEXT(GLint size
, GLenum type
,
336 GLsizei stride
, const GLvoid
*ptr
)
340 GET_CURRENT_CONTEXT(ctx
);
341 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
343 if (size
!= 3 && size
!= 4) {
344 if (!ctx
->Extensions
.EXT_vertex_array_bgra
|| size
!= GL_BGRA
) {
345 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSecondaryColorPointer(size)");
350 _mesa_error( ctx
, GL_INVALID_VALUE
, "glSecondaryColorPointer(stride)" );
354 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
355 _mesa_debug(ctx
, "glSecondaryColorPointer( sz %d type %s stride %d )\n",
356 size
, _mesa_lookup_enum_by_nr( type
), stride
);
358 if (size
== GL_BGRA
) {
359 if (type
!= GL_UNSIGNED_BYTE
) {
360 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorPointer(GL_BGRA/GLubyte)");
372 elementSize
= size
* sizeof(GLbyte
);
374 case GL_UNSIGNED_BYTE
:
375 elementSize
= size
* sizeof(GLubyte
);
378 elementSize
= size
* sizeof(GLshort
);
380 case GL_UNSIGNED_SHORT
:
381 elementSize
= size
* sizeof(GLushort
);
384 elementSize
= size
* sizeof(GLint
);
386 case GL_UNSIGNED_INT
:
387 elementSize
= size
* sizeof(GLuint
);
390 elementSize
= size
* sizeof(GLfloat
);
393 elementSize
= size
* sizeof(GLdouble
);
396 _mesa_error( ctx
, GL_INVALID_ENUM
, "glSecondaryColorPointer(type)" );
400 update_array(ctx
, &ctx
->Array
.ArrayObj
->SecondaryColor
, _NEW_ARRAY_COLOR1
,
401 elementSize
, size
, type
, format
, stride
, GL_TRUE
, ptr
);
403 if (ctx
->Driver
.SecondaryColorPointer
)
404 ctx
->Driver
.SecondaryColorPointer( ctx
, size
, type
, stride
, ptr
);
409 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
413 GET_CURRENT_CONTEXT(ctx
);
414 const GLuint unit
= ctx
->Array
.ActiveTexture
;
415 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
417 if (size
< 1 || size
> 4) {
418 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexCoordPointer(size)" );
422 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexCoordPointer(stride)" );
426 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
427 _mesa_debug(ctx
, "glTexCoordPointer(unit %u sz %d type %s stride %d)\n",
428 unit
, size
, _mesa_lookup_enum_by_nr( type
), stride
);
430 /* always need to check that <type> is legal */
433 elementSize
= size
* sizeof(GLshort
);
436 elementSize
= size
* sizeof(GLint
);
439 elementSize
= size
* sizeof(GLfloat
);
442 elementSize
= size
* sizeof(GLdouble
);
446 elementSize
= size
* sizeof(GLfixed
);
449 #if FEATURE_vertex_array_byte
451 elementSize
= size
* sizeof(GLbyte
);
455 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexCoordPointer(type)" );
459 update_array(ctx
, &ctx
->Array
.ArrayObj
->TexCoord
[unit
],
460 _NEW_ARRAY_TEXCOORD(unit
),
461 elementSize
, size
, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
);
463 if (ctx
->Driver
.TexCoordPointer
)
464 ctx
->Driver
.TexCoordPointer( ctx
, size
, type
, stride
, ptr
);
469 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
471 GET_CURRENT_CONTEXT(ctx
);
472 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
475 _mesa_error( ctx
, GL_INVALID_VALUE
, "glEdgeFlagPointer(stride)" );
479 update_array(ctx
, &ctx
->Array
.ArrayObj
->EdgeFlag
, _NEW_ARRAY_EDGEFLAG
,
480 sizeof(GLboolean
), 1, GL_UNSIGNED_BYTE
, GL_RGBA
,
481 stride
, GL_FALSE
, ptr
);
483 if (ctx
->Driver
.EdgeFlagPointer
)
484 ctx
->Driver
.EdgeFlagPointer( ctx
, stride
, ptr
);
489 _mesa_PointSizePointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
492 GET_CURRENT_CONTEXT(ctx
);
493 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
496 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPointSizePointer(stride)" );
502 elementSize
= sizeof(GLfloat
);
506 elementSize
= sizeof(GLfixed
);
510 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPointSizePointer(type)" );
514 update_array(ctx
, &ctx
->Array
.ArrayObj
->PointSize
, _NEW_ARRAY_POINT_SIZE
,
515 elementSize
, 1, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
);
519 #if FEATURE_NV_vertex_program
521 * Set a vertex attribute array.
522 * Note that these arrays DO alias the conventional GL vertex arrays
523 * (position, normal, color, fog, texcoord, etc).
524 * The generic attribute slots at #16 and above are not touched.
527 _mesa_VertexAttribPointerNV(GLuint index
, GLint size
, GLenum type
,
528 GLsizei stride
, const GLvoid
*ptr
)
530 GLboolean normalized
= GL_FALSE
;
533 GET_CURRENT_CONTEXT(ctx
);
534 ASSERT_OUTSIDE_BEGIN_END(ctx
);
536 if (index
>= MAX_NV_VERTEX_PROGRAM_INPUTS
) {
537 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(index)");
541 if (size
< 1 || size
> 4) {
542 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(size)");
547 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(stride)");
551 if (type
== GL_UNSIGNED_BYTE
&& size
!= 4) {
552 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(size!=4)");
556 if (size
== GL_BGRA
) {
557 if (type
!= GL_UNSIGNED_BYTE
) {
558 _mesa_error(ctx
, GL_INVALID_VALUE
,
559 "glVertexAttribPointerNV(GL_BGRA/type)");
565 normalized
= GL_TRUE
;
571 /* check for valid 'type' and compute StrideB right away */
573 case GL_UNSIGNED_BYTE
:
574 normalized
= GL_TRUE
;
575 elementSize
= size
* sizeof(GLubyte
);
578 elementSize
= size
* sizeof(GLshort
);
581 elementSize
= size
* sizeof(GLfloat
);
584 elementSize
= size
* sizeof(GLdouble
);
587 _mesa_error( ctx
, GL_INVALID_ENUM
, "glVertexAttribPointerNV(type)" );
591 update_array(ctx
, &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
592 _NEW_ARRAY_ATTRIB(index
),
593 elementSize
, size
, type
, format
, stride
, normalized
, ptr
);
595 if (ctx
->Driver
.VertexAttribPointer
)
596 ctx
->Driver
.VertexAttribPointer( ctx
, index
, size
, type
, stride
, ptr
);
601 #if FEATURE_ARB_vertex_program
603 * Set a generic vertex attribute array.
604 * Note that these arrays DO NOT alias the conventional GL vertex arrays
605 * (position, normal, color, fog, texcoord, etc).
608 _mesa_VertexAttribPointerARB(GLuint index
, GLint size
, GLenum type
,
609 GLboolean normalized
,
610 GLsizei stride
, const GLvoid
*ptr
)
614 GET_CURRENT_CONTEXT(ctx
);
615 ASSERT_OUTSIDE_BEGIN_END(ctx
);
617 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
618 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
622 if (size
< 1 || size
> 4) {
623 if (!ctx
->Extensions
.EXT_vertex_array_bgra
|| size
!= GL_BGRA
) {
624 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(size)");
630 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(stride)");
634 if (size
== GL_BGRA
) {
635 if (type
!= GL_UNSIGNED_BYTE
) {
636 _mesa_error(ctx
, GL_INVALID_VALUE
,
637 "glVertexAttribPointerARB(GL_BGRA/type)");
640 if (normalized
!= GL_TRUE
) {
641 _mesa_error(ctx
, GL_INVALID_VALUE
,
642 "glVertexAttribPointerARB(GL_BGRA/normalized)");
653 /* check for valid 'type' and compute StrideB right away */
654 /* NOTE: more types are supported here than in the NV extension */
657 elementSize
= size
* sizeof(GLbyte
);
659 case GL_UNSIGNED_BYTE
:
660 elementSize
= size
* sizeof(GLubyte
);
663 elementSize
= size
* sizeof(GLshort
);
665 case GL_UNSIGNED_SHORT
:
666 elementSize
= size
* sizeof(GLushort
);
669 elementSize
= size
* sizeof(GLint
);
671 case GL_UNSIGNED_INT
:
672 elementSize
= size
* sizeof(GLuint
);
675 elementSize
= size
* sizeof(GLfloat
);
678 elementSize
= size
* sizeof(GLdouble
);
682 elementSize
= size
* sizeof(GLfixed
);
686 _mesa_error( ctx
, GL_INVALID_ENUM
, "glVertexAttribPointerARB(type)" );
690 update_array(ctx
, &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
691 _NEW_ARRAY_ATTRIB(index
),
692 elementSize
, size
, type
, format
, stride
, normalized
, ptr
);
694 if (ctx
->Driver
.VertexAttribPointer
)
695 ctx
->Driver
.VertexAttribPointer(ctx
, index
, size
, type
, stride
, ptr
);
701 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
702 GLsizei count
, const GLvoid
*ptr
)
705 _mesa_VertexPointer(size
, type
, stride
, ptr
);
710 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
714 _mesa_NormalPointer(type
, stride
, ptr
);
719 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
723 _mesa_ColorPointer(size
, type
, stride
, ptr
);
728 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
732 _mesa_IndexPointer(type
, stride
, ptr
);
737 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
738 GLsizei count
, const GLvoid
*ptr
)
741 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
746 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
749 _mesa_EdgeFlagPointer(stride
, ptr
);
754 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
756 GET_CURRENT_CONTEXT(ctx
);
757 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
758 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
759 GLenum ctype
= 0; /* color type */
760 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
761 const GLint toffset
= 0; /* always zero */
762 GLint defstride
; /* default stride */
765 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
768 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
771 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
777 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
778 tcomps
= 0; ccomps
= 0; vcomps
= 2;
783 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
784 tcomps
= 0; ccomps
= 0; vcomps
= 3;
789 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
790 tcomps
= 0; ccomps
= 4; vcomps
= 2;
791 ctype
= GL_UNSIGNED_BYTE
;
797 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
798 tcomps
= 0; ccomps
= 4; vcomps
= 3;
799 ctype
= GL_UNSIGNED_BYTE
;
805 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
806 tcomps
= 0; ccomps
= 3; vcomps
= 3;
813 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
814 tcomps
= 0; ccomps
= 0; vcomps
= 3;
820 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
821 tcomps
= 0; ccomps
= 4; vcomps
= 3;
829 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
830 tcomps
= 2; ccomps
= 0; vcomps
= 3;
835 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
836 tcomps
= 4; ccomps
= 0; vcomps
= 4;
840 case GL_T2F_C4UB_V3F
:
841 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
842 tcomps
= 2; ccomps
= 4; vcomps
= 3;
843 ctype
= GL_UNSIGNED_BYTE
;
849 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
850 tcomps
= 2; ccomps
= 3; vcomps
= 3;
857 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
858 tcomps
= 2; ccomps
= 0; vcomps
= 3;
863 case GL_T2F_C4F_N3F_V3F
:
864 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
865 tcomps
= 2; ccomps
= 4; vcomps
= 3;
872 case GL_T4F_C4F_N3F_V4F
:
873 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
874 tcomps
= 4; ccomps
= 4; vcomps
= 4;
882 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
890 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
891 _mesa_DisableClientState( GL_INDEX_ARRAY
);
892 /* XXX also disable secondary color and generic arrays? */
896 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
897 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
898 (GLubyte
*) pointer
+ toffset
);
901 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
906 _mesa_EnableClientState( GL_COLOR_ARRAY
);
907 _mesa_ColorPointer( ccomps
, ctype
, stride
,
908 (GLubyte
*) pointer
+ coffset
);
911 _mesa_DisableClientState( GL_COLOR_ARRAY
);
917 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
918 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
921 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
925 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
926 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
927 (GLubyte
*) pointer
+ voffset
);
932 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
934 GET_CURRENT_CONTEXT(ctx
);
935 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
937 if (MESA_VERBOSE
& VERBOSE_API
)
938 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
941 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
945 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
948 if (ctx
->Array
.LockCount
!= 0) {
949 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
953 ctx
->Array
.LockFirst
= first
;
954 ctx
->Array
.LockCount
= count
;
956 ctx
->NewState
|= _NEW_ARRAY
;
957 ctx
->Array
.NewState
|= _NEW_ARRAY_ALL
;
959 if (ctx
->Driver
.LockArraysEXT
)
960 ctx
->Driver
.LockArraysEXT( ctx
, first
, count
);
965 _mesa_UnlockArraysEXT( void )
967 GET_CURRENT_CONTEXT(ctx
);
968 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
970 if (MESA_VERBOSE
& VERBOSE_API
)
971 _mesa_debug(ctx
, "glUnlockArrays\n");
973 if (ctx
->Array
.LockCount
== 0) {
974 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
978 ctx
->Array
.LockFirst
= 0;
979 ctx
->Array
.LockCount
= 0;
980 ctx
->NewState
|= _NEW_ARRAY
;
981 ctx
->Array
.NewState
|= _NEW_ARRAY_ALL
;
983 if (ctx
->Driver
.UnlockArraysEXT
)
984 ctx
->Driver
.UnlockArraysEXT( ctx
);
988 /* GL_EXT_multi_draw_arrays */
989 /* Somebody forgot to spec the first and count parameters as const! <sigh> */
991 _mesa_MultiDrawArraysEXT( GLenum mode
, GLint
*first
,
992 GLsizei
*count
, GLsizei primcount
)
994 GET_CURRENT_CONTEXT(ctx
);
997 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
999 for (i
= 0; i
< primcount
; i
++) {
1001 CALL_DrawArrays(ctx
->Exec
, (mode
, first
[i
], count
[i
]));
1007 /* GL_EXT_multi_draw_arrays */
1009 _mesa_MultiDrawElementsEXT( GLenum mode
, const GLsizei
*count
, GLenum type
,
1010 const GLvoid
**indices
, GLsizei primcount
)
1012 GET_CURRENT_CONTEXT(ctx
);
1015 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1017 for (i
= 0; i
< primcount
; i
++) {
1019 CALL_DrawElements(ctx
->Exec
, (mode
, count
[i
], type
, indices
[i
]));
1025 /* GL_IBM_multimode_draw_arrays */
1027 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1028 const GLsizei
* count
,
1029 GLsizei primcount
, GLint modestride
)
1031 GET_CURRENT_CONTEXT(ctx
);
1034 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1036 for ( i
= 0 ; i
< primcount
; i
++ ) {
1037 if ( count
[i
] > 0 ) {
1038 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1039 CALL_DrawArrays(ctx
->Exec
, ( m
, first
[i
], count
[i
] ));
1045 /* GL_IBM_multimode_draw_arrays */
1047 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1048 GLenum type
, const GLvoid
* const * indices
,
1049 GLsizei primcount
, GLint modestride
)
1051 GET_CURRENT_CONTEXT(ctx
);
1054 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1056 /* XXX not sure about ARB_vertex_buffer_object handling here */
1058 for ( i
= 0 ; i
< primcount
; i
++ ) {
1059 if ( count
[i
] > 0 ) {
1060 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1061 CALL_DrawElements(ctx
->Exec
, ( m
, count
[i
], type
, indices
[i
] ));
1068 * Print vertex array's fields.
1071 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1074 _mesa_printf(" %s[%d]: ", name
, index
);
1076 _mesa_printf(" %s: ", name
);
1077 _mesa_printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %u), MaxElem=%u\n",
1078 array
->Ptr
, array
->Type
, array
->Size
,
1079 array
->_ElementSize
, array
->StrideB
,
1080 array
->BufferObj
->Name
, array
->BufferObj
->Size
,
1081 array
->_MaxElement
);
1086 * Print current vertex object/array info. For debug.
1089 _mesa_print_arrays(GLcontext
*ctx
)
1091 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
1094 _mesa_update_array_object_max_element(ctx
, arrayObj
);
1096 _mesa_printf("Array Object %u\n", arrayObj
->Name
);
1097 if (arrayObj
->Vertex
.Enabled
)
1098 print_array("Vertex", -1, &arrayObj
->Vertex
);
1099 if (arrayObj
->Normal
.Enabled
)
1100 print_array("Normal", -1, &arrayObj
->Normal
);
1101 if (arrayObj
->Color
.Enabled
)
1102 print_array("Color", -1, &arrayObj
->Color
);
1103 for (i
= 0; i
< Elements(arrayObj
->TexCoord
); i
++)
1104 if (arrayObj
->TexCoord
[i
].Enabled
)
1105 print_array("TexCoord", i
, &arrayObj
->TexCoord
[i
]);
1106 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++)
1107 if (arrayObj
->VertexAttrib
[i
].Enabled
)
1108 print_array("Attrib", i
, &arrayObj
->VertexAttrib
[i
]);
1109 _mesa_printf(" _MaxElement = %u\n", arrayObj
->_MaxElement
);
1114 * Initialize vertex array state for given context.
1117 _mesa_init_varray(GLcontext
*ctx
)
1119 ctx
->Array
.DefaultArrayObj
= _mesa_new_array_object(ctx
, 0);
1120 _mesa_reference_array_object(ctx
, &ctx
->Array
.ArrayObj
,
1121 ctx
->Array
.DefaultArrayObj
);
1122 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */