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=%s)",
139 _mesa_lookup_enum_by_nr(type
));
143 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->Vertex
, _NEW_ARRAY_VERTEX
,
144 elementSize
, size
, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
))
147 if (ctx
->Driver
.VertexPointer
)
148 ctx
->Driver
.VertexPointer( ctx
, size
, type
, stride
, ptr
);
153 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
156 GET_CURRENT_CONTEXT(ctx
);
157 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
160 _mesa_error( ctx
, GL_INVALID_VALUE
, "glNormalPointer(stride)" );
164 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
165 _mesa_debug(ctx
, "glNormalPointer( type %s stride %d )\n",
166 _mesa_lookup_enum_by_nr( type
), stride
);
170 elementSize
= 3 * sizeof(GLbyte
);
173 elementSize
= 3 * sizeof(GLshort
);
176 elementSize
= 3 * sizeof(GLint
);
179 elementSize
= 3 * sizeof(GLfloat
);
182 elementSize
= 3 * sizeof(GLdouble
);
186 elementSize
= 3 * sizeof(GLfixed
);
190 _mesa_error( ctx
, GL_INVALID_ENUM
, "glNormalPointer(type=%s)",
191 _mesa_lookup_enum_by_nr(type
));
195 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->Normal
, _NEW_ARRAY_NORMAL
,
196 elementSize
, 3, type
, GL_RGBA
, stride
, GL_TRUE
, ptr
))
199 if (ctx
->Driver
.NormalPointer
)
200 ctx
->Driver
.NormalPointer( ctx
, type
, stride
, ptr
);
205 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
209 GET_CURRENT_CONTEXT(ctx
);
210 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
212 if (size
< 3 || size
> 4) {
213 if (!ctx
->Extensions
.EXT_vertex_array_bgra
|| size
!= GL_BGRA
) {
214 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorPointer(size)");
219 _mesa_error( ctx
, GL_INVALID_VALUE
, "glColorPointer(stride)" );
223 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
224 _mesa_debug(ctx
, "glColorPointer( sz %d type %s stride %d )\n", size
,
225 _mesa_lookup_enum_by_nr( type
), stride
);
227 if (size
== GL_BGRA
) {
228 if (type
!= GL_UNSIGNED_BYTE
) {
229 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorPointer(GL_BGRA/GLubyte)");
241 elementSize
= size
* sizeof(GLbyte
);
243 case GL_UNSIGNED_BYTE
:
244 elementSize
= size
* sizeof(GLubyte
);
247 elementSize
= size
* sizeof(GLshort
);
249 case GL_UNSIGNED_SHORT
:
250 elementSize
= size
* sizeof(GLushort
);
253 elementSize
= size
* sizeof(GLint
);
255 case GL_UNSIGNED_INT
:
256 elementSize
= size
* sizeof(GLuint
);
259 elementSize
= size
* sizeof(GLfloat
);
262 elementSize
= size
* sizeof(GLdouble
);
266 elementSize
= size
* sizeof(GLfixed
);
270 _mesa_error( ctx
, GL_INVALID_ENUM
, "glColorPointer(type=%s)",
271 _mesa_lookup_enum_by_nr(type
));
275 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->Color
, _NEW_ARRAY_COLOR0
,
276 elementSize
, size
, type
, format
, stride
, GL_TRUE
, ptr
))
279 if (ctx
->Driver
.ColorPointer
)
280 ctx
->Driver
.ColorPointer( ctx
, size
, type
, stride
, ptr
);
285 _mesa_FogCoordPointerEXT(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
288 GET_CURRENT_CONTEXT(ctx
);
289 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
292 _mesa_error( ctx
, GL_INVALID_VALUE
, "glFogCoordPointer(stride)" );
298 elementSize
= sizeof(GLfloat
);
301 elementSize
= sizeof(GLdouble
);
304 _mesa_error( ctx
, GL_INVALID_ENUM
, "glFogCoordPointer(type)" );
308 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->FogCoord
, _NEW_ARRAY_FOGCOORD
,
309 elementSize
, 1, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
))
312 if (ctx
->Driver
.FogCoordPointer
)
313 ctx
->Driver
.FogCoordPointer( ctx
, type
, stride
, ptr
);
318 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
321 GET_CURRENT_CONTEXT(ctx
);
322 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
325 _mesa_error( ctx
, GL_INVALID_VALUE
, "glIndexPointer(stride)" );
330 case GL_UNSIGNED_BYTE
:
331 elementSize
= sizeof(GLubyte
);
334 elementSize
= sizeof(GLshort
);
337 elementSize
= sizeof(GLint
);
340 elementSize
= sizeof(GLfloat
);
343 elementSize
= sizeof(GLdouble
);
346 _mesa_error( ctx
, GL_INVALID_ENUM
, "glIndexPointer(type)" );
350 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->Index
, _NEW_ARRAY_INDEX
,
351 elementSize
, 1, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
))
354 if (ctx
->Driver
.IndexPointer
)
355 ctx
->Driver
.IndexPointer( ctx
, type
, stride
, ptr
);
360 _mesa_SecondaryColorPointerEXT(GLint size
, GLenum type
,
361 GLsizei stride
, const GLvoid
*ptr
)
365 GET_CURRENT_CONTEXT(ctx
);
366 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
368 if (size
!= 3 && size
!= 4) {
369 if (!ctx
->Extensions
.EXT_vertex_array_bgra
|| size
!= GL_BGRA
) {
370 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSecondaryColorPointer(size)");
375 _mesa_error( ctx
, GL_INVALID_VALUE
, "glSecondaryColorPointer(stride)" );
379 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
380 _mesa_debug(ctx
, "glSecondaryColorPointer( sz %d type %s stride %d )\n",
381 size
, _mesa_lookup_enum_by_nr( type
), stride
);
383 if (size
== GL_BGRA
) {
384 if (type
!= GL_UNSIGNED_BYTE
) {
385 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorPointer(GL_BGRA/GLubyte)");
397 elementSize
= size
* sizeof(GLbyte
);
399 case GL_UNSIGNED_BYTE
:
400 elementSize
= size
* sizeof(GLubyte
);
403 elementSize
= size
* sizeof(GLshort
);
405 case GL_UNSIGNED_SHORT
:
406 elementSize
= size
* sizeof(GLushort
);
409 elementSize
= size
* sizeof(GLint
);
411 case GL_UNSIGNED_INT
:
412 elementSize
= size
* sizeof(GLuint
);
415 elementSize
= size
* sizeof(GLfloat
);
418 elementSize
= size
* sizeof(GLdouble
);
421 _mesa_error( ctx
, GL_INVALID_ENUM
, "glSecondaryColorPointer(type=%s)",
422 _mesa_lookup_enum_by_nr(type
));
426 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->SecondaryColor
,
427 _NEW_ARRAY_COLOR1
, elementSize
, size
, type
,
428 format
, stride
, GL_TRUE
, ptr
))
431 if (ctx
->Driver
.SecondaryColorPointer
)
432 ctx
->Driver
.SecondaryColorPointer( ctx
, size
, type
, stride
, ptr
);
437 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
441 GET_CURRENT_CONTEXT(ctx
);
442 const GLuint unit
= ctx
->Array
.ActiveTexture
;
443 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
445 if (size
< 1 || size
> 4) {
446 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexCoordPointer(size)" );
450 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexCoordPointer(stride)" );
454 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
455 _mesa_debug(ctx
, "glTexCoordPointer(unit %u sz %d type %s stride %d)\n",
456 unit
, size
, _mesa_lookup_enum_by_nr( type
), stride
);
458 /* always need to check that <type> is legal */
461 elementSize
= size
* sizeof(GLshort
);
464 elementSize
= size
* sizeof(GLint
);
467 elementSize
= size
* sizeof(GLfloat
);
470 elementSize
= size
* sizeof(GLdouble
);
474 elementSize
= size
* sizeof(GLfixed
);
477 #if FEATURE_vertex_array_byte
479 elementSize
= size
* sizeof(GLbyte
);
483 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexCoordPointer(type=%s)",
484 _mesa_lookup_enum_by_nr(type
));
488 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->TexCoord
[unit
],
489 _NEW_ARRAY_TEXCOORD(unit
),
490 elementSize
, size
, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
))
493 if (ctx
->Driver
.TexCoordPointer
)
494 ctx
->Driver
.TexCoordPointer( ctx
, size
, type
, stride
, ptr
);
499 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
501 GET_CURRENT_CONTEXT(ctx
);
502 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
505 _mesa_error( ctx
, GL_INVALID_VALUE
, "glEdgeFlagPointer(stride)" );
509 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->EdgeFlag
, _NEW_ARRAY_EDGEFLAG
,
510 sizeof(GLboolean
), 1, GL_UNSIGNED_BYTE
, GL_RGBA
,
511 stride
, GL_FALSE
, ptr
))
514 if (ctx
->Driver
.EdgeFlagPointer
)
515 ctx
->Driver
.EdgeFlagPointer( ctx
, stride
, ptr
);
520 _mesa_PointSizePointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
523 GET_CURRENT_CONTEXT(ctx
);
524 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
527 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPointSizePointer(stride)" );
533 elementSize
= sizeof(GLfloat
);
537 elementSize
= sizeof(GLfixed
);
541 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPointSizePointer(type)" );
545 update_array(ctx
, &ctx
->Array
.ArrayObj
->PointSize
, _NEW_ARRAY_POINT_SIZE
,
546 elementSize
, 1, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
);
550 #if FEATURE_NV_vertex_program
552 * Set a vertex attribute array.
553 * Note that these arrays DO alias the conventional GL vertex arrays
554 * (position, normal, color, fog, texcoord, etc).
555 * The generic attribute slots at #16 and above are not touched.
558 _mesa_VertexAttribPointerNV(GLuint index
, GLint size
, GLenum type
,
559 GLsizei stride
, const GLvoid
*ptr
)
561 GLboolean normalized
= GL_FALSE
;
564 GET_CURRENT_CONTEXT(ctx
);
565 ASSERT_OUTSIDE_BEGIN_END(ctx
);
567 if (index
>= MAX_NV_VERTEX_PROGRAM_INPUTS
) {
568 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(index)");
572 if (size
< 1 || size
> 4) {
573 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(size)");
578 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(stride)");
582 if (type
== GL_UNSIGNED_BYTE
&& size
!= 4) {
583 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(size!=4)");
587 if (size
== GL_BGRA
) {
588 if (type
!= GL_UNSIGNED_BYTE
) {
589 _mesa_error(ctx
, GL_INVALID_VALUE
,
590 "glVertexAttribPointerNV(GL_BGRA/type)");
596 normalized
= GL_TRUE
;
602 /* check for valid 'type' and compute StrideB right away */
604 case GL_UNSIGNED_BYTE
:
605 normalized
= GL_TRUE
;
606 elementSize
= size
* sizeof(GLubyte
);
609 elementSize
= size
* sizeof(GLshort
);
612 elementSize
= size
* sizeof(GLfloat
);
615 elementSize
= size
* sizeof(GLdouble
);
618 _mesa_error( ctx
, GL_INVALID_ENUM
, "glVertexAttribPointerNV(type=%s)",
619 _mesa_lookup_enum_by_nr(type
));
623 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
624 _NEW_ARRAY_ATTRIB(index
),
625 elementSize
, size
, type
, format
, stride
, normalized
, ptr
))
628 if (ctx
->Driver
.VertexAttribPointer
)
629 ctx
->Driver
.VertexAttribPointer( ctx
, index
, size
, type
, stride
, ptr
);
634 #if FEATURE_ARB_vertex_program
636 * Set a generic vertex attribute array.
637 * Note that these arrays DO NOT alias the conventional GL vertex arrays
638 * (position, normal, color, fog, texcoord, etc).
641 _mesa_VertexAttribPointerARB(GLuint index
, GLint size
, GLenum type
,
642 GLboolean normalized
,
643 GLsizei stride
, const GLvoid
*ptr
)
647 GET_CURRENT_CONTEXT(ctx
);
648 ASSERT_OUTSIDE_BEGIN_END(ctx
);
650 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
651 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
655 if (size
< 1 || size
> 4) {
656 if (!ctx
->Extensions
.EXT_vertex_array_bgra
|| size
!= GL_BGRA
) {
657 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(size)");
663 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(stride)");
667 if (size
== GL_BGRA
) {
668 if (type
!= GL_UNSIGNED_BYTE
) {
669 _mesa_error(ctx
, GL_INVALID_VALUE
,
670 "glVertexAttribPointerARB(GL_BGRA/type)");
673 if (normalized
!= GL_TRUE
) {
674 _mesa_error(ctx
, GL_INVALID_VALUE
,
675 "glVertexAttribPointerARB(GL_BGRA/normalized)");
686 /* check for valid 'type' and compute StrideB right away */
687 /* NOTE: more types are supported here than in the NV extension */
690 elementSize
= size
* sizeof(GLbyte
);
692 case GL_UNSIGNED_BYTE
:
693 elementSize
= size
* sizeof(GLubyte
);
696 elementSize
= size
* sizeof(GLshort
);
698 case GL_UNSIGNED_SHORT
:
699 elementSize
= size
* sizeof(GLushort
);
702 elementSize
= size
* sizeof(GLint
);
704 case GL_UNSIGNED_INT
:
705 elementSize
= size
* sizeof(GLuint
);
708 elementSize
= size
* sizeof(GLfloat
);
711 elementSize
= size
* sizeof(GLdouble
);
715 elementSize
= size
* sizeof(GLfixed
);
719 _mesa_error( ctx
, GL_INVALID_ENUM
, "glVertexAttribPointerARB(type)" );
723 if (!update_array(ctx
, &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
724 _NEW_ARRAY_ATTRIB(index
),
725 elementSize
, size
, type
, format
, stride
, normalized
, ptr
))
728 if (ctx
->Driver
.VertexAttribPointer
)
729 ctx
->Driver
.VertexAttribPointer(ctx
, index
, size
, type
, stride
, ptr
);
735 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
736 GLsizei count
, const GLvoid
*ptr
)
739 _mesa_VertexPointer(size
, type
, stride
, ptr
);
744 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
748 _mesa_NormalPointer(type
, stride
, ptr
);
753 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
757 _mesa_ColorPointer(size
, type
, stride
, ptr
);
762 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
766 _mesa_IndexPointer(type
, stride
, ptr
);
771 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
772 GLsizei count
, const GLvoid
*ptr
)
775 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
780 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
783 _mesa_EdgeFlagPointer(stride
, ptr
);
788 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
790 GET_CURRENT_CONTEXT(ctx
);
791 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
792 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
793 GLenum ctype
= 0; /* color type */
794 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
795 const GLint toffset
= 0; /* always zero */
796 GLint defstride
; /* default stride */
799 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
802 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
805 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
811 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
812 tcomps
= 0; ccomps
= 0; vcomps
= 2;
817 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
818 tcomps
= 0; ccomps
= 0; vcomps
= 3;
823 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
824 tcomps
= 0; ccomps
= 4; vcomps
= 2;
825 ctype
= GL_UNSIGNED_BYTE
;
831 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
832 tcomps
= 0; ccomps
= 4; vcomps
= 3;
833 ctype
= GL_UNSIGNED_BYTE
;
839 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
840 tcomps
= 0; ccomps
= 3; vcomps
= 3;
847 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
848 tcomps
= 0; ccomps
= 0; vcomps
= 3;
854 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
855 tcomps
= 0; ccomps
= 4; vcomps
= 3;
863 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
864 tcomps
= 2; ccomps
= 0; vcomps
= 3;
869 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
870 tcomps
= 4; ccomps
= 0; vcomps
= 4;
874 case GL_T2F_C4UB_V3F
:
875 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
876 tcomps
= 2; ccomps
= 4; vcomps
= 3;
877 ctype
= GL_UNSIGNED_BYTE
;
883 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
884 tcomps
= 2; ccomps
= 3; vcomps
= 3;
891 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
892 tcomps
= 2; ccomps
= 0; vcomps
= 3;
897 case GL_T2F_C4F_N3F_V3F
:
898 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
899 tcomps
= 2; ccomps
= 4; vcomps
= 3;
906 case GL_T4F_C4F_N3F_V4F
:
907 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
908 tcomps
= 4; ccomps
= 4; vcomps
= 4;
916 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
924 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
925 _mesa_DisableClientState( GL_INDEX_ARRAY
);
926 /* XXX also disable secondary color and generic arrays? */
930 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
931 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
932 (GLubyte
*) pointer
+ toffset
);
935 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
940 _mesa_EnableClientState( GL_COLOR_ARRAY
);
941 _mesa_ColorPointer( ccomps
, ctype
, stride
,
942 (GLubyte
*) pointer
+ coffset
);
945 _mesa_DisableClientState( GL_COLOR_ARRAY
);
951 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
952 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
955 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
959 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
960 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
961 (GLubyte
*) pointer
+ voffset
);
966 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
968 GET_CURRENT_CONTEXT(ctx
);
969 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
971 if (MESA_VERBOSE
& VERBOSE_API
)
972 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
975 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
979 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
982 if (ctx
->Array
.LockCount
!= 0) {
983 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
987 ctx
->Array
.LockFirst
= first
;
988 ctx
->Array
.LockCount
= count
;
990 ctx
->NewState
|= _NEW_ARRAY
;
991 ctx
->Array
.NewState
|= _NEW_ARRAY_ALL
;
993 if (ctx
->Driver
.LockArraysEXT
)
994 ctx
->Driver
.LockArraysEXT( ctx
, first
, count
);
999 _mesa_UnlockArraysEXT( void )
1001 GET_CURRENT_CONTEXT(ctx
);
1002 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1004 if (MESA_VERBOSE
& VERBOSE_API
)
1005 _mesa_debug(ctx
, "glUnlockArrays\n");
1007 if (ctx
->Array
.LockCount
== 0) {
1008 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1012 ctx
->Array
.LockFirst
= 0;
1013 ctx
->Array
.LockCount
= 0;
1014 ctx
->NewState
|= _NEW_ARRAY
;
1015 ctx
->Array
.NewState
|= _NEW_ARRAY_ALL
;
1017 if (ctx
->Driver
.UnlockArraysEXT
)
1018 ctx
->Driver
.UnlockArraysEXT( ctx
);
1022 /* GL_EXT_multi_draw_arrays */
1023 /* Somebody forgot to spec the first and count parameters as const! <sigh> */
1025 _mesa_MultiDrawArraysEXT( GLenum mode
, GLint
*first
,
1026 GLsizei
*count
, GLsizei primcount
)
1028 GET_CURRENT_CONTEXT(ctx
);
1031 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1033 for (i
= 0; i
< primcount
; i
++) {
1035 CALL_DrawArrays(ctx
->Exec
, (mode
, first
[i
], count
[i
]));
1041 /* GL_IBM_multimode_draw_arrays */
1043 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1044 const GLsizei
* count
,
1045 GLsizei primcount
, GLint modestride
)
1047 GET_CURRENT_CONTEXT(ctx
);
1050 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1052 for ( i
= 0 ; i
< primcount
; i
++ ) {
1053 if ( count
[i
] > 0 ) {
1054 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1055 CALL_DrawArrays(ctx
->Exec
, ( m
, first
[i
], count
[i
] ));
1061 /* GL_IBM_multimode_draw_arrays */
1063 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1064 GLenum type
, const GLvoid
* const * indices
,
1065 GLsizei primcount
, GLint modestride
)
1067 GET_CURRENT_CONTEXT(ctx
);
1070 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1072 /* XXX not sure about ARB_vertex_buffer_object handling here */
1074 for ( i
= 0 ; i
< primcount
; i
++ ) {
1075 if ( count
[i
] > 0 ) {
1076 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1077 CALL_DrawElements(ctx
->Exec
, ( m
, count
[i
], type
, indices
[i
] ));
1084 * Copy one client vertex array to another.
1087 _mesa_copy_client_array(GLcontext
*ctx
,
1088 struct gl_client_array
*dst
,
1089 struct gl_client_array
*src
)
1091 dst
->Size
= src
->Size
;
1092 dst
->Type
= src
->Type
;
1093 dst
->Format
= src
->Format
;
1094 dst
->Stride
= src
->Stride
;
1095 dst
->StrideB
= src
->StrideB
;
1096 dst
->Ptr
= src
->Ptr
;
1097 dst
->Enabled
= src
->Enabled
;
1098 dst
->Normalized
= src
->Normalized
;
1099 dst
->_ElementSize
= src
->_ElementSize
;
1100 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1101 dst
->_MaxElement
= src
->_MaxElement
;
1107 * Print vertex array's fields.
1110 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1113 _mesa_printf(" %s[%d]: ", name
, index
);
1115 _mesa_printf(" %s: ", name
);
1116 _mesa_printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %u), MaxElem=%u\n",
1117 array
->Ptr
, array
->Type
, array
->Size
,
1118 array
->_ElementSize
, array
->StrideB
,
1119 array
->BufferObj
->Name
, array
->BufferObj
->Size
,
1120 array
->_MaxElement
);
1125 * Print current vertex object/array info. For debug.
1128 _mesa_print_arrays(GLcontext
*ctx
)
1130 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
1133 _mesa_update_array_object_max_element(ctx
, arrayObj
);
1135 _mesa_printf("Array Object %u\n", arrayObj
->Name
);
1136 if (arrayObj
->Vertex
.Enabled
)
1137 print_array("Vertex", -1, &arrayObj
->Vertex
);
1138 if (arrayObj
->Normal
.Enabled
)
1139 print_array("Normal", -1, &arrayObj
->Normal
);
1140 if (arrayObj
->Color
.Enabled
)
1141 print_array("Color", -1, &arrayObj
->Color
);
1142 for (i
= 0; i
< Elements(arrayObj
->TexCoord
); i
++)
1143 if (arrayObj
->TexCoord
[i
].Enabled
)
1144 print_array("TexCoord", i
, &arrayObj
->TexCoord
[i
]);
1145 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++)
1146 if (arrayObj
->VertexAttrib
[i
].Enabled
)
1147 print_array("Attrib", i
, &arrayObj
->VertexAttrib
[i
]);
1148 _mesa_printf(" _MaxElement = %u\n", arrayObj
->_MaxElement
);
1153 * Initialize vertex array state for given context.
1156 _mesa_init_varray(GLcontext
*ctx
)
1158 ctx
->Array
.DefaultArrayObj
= _mesa_new_array_object(ctx
, 0);
1159 _mesa_reference_array_object(ctx
, &ctx
->Array
.ArrayObj
,
1160 ctx
->Array
.DefaultArrayObj
);
1161 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1163 ctx
->Array
.Objects
= _mesa_NewHashTable();
1168 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1171 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1173 struct gl_array_object
*arrayObj
= (struct gl_array_object
*) data
;
1174 GLcontext
*ctx
= (GLcontext
*) userData
;
1175 _mesa_delete_array_object(ctx
, arrayObj
);
1180 * Free vertex array state for given context.
1183 _mesa_free_varray_data(GLcontext
*ctx
)
1185 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1186 _mesa_DeleteHashTable(ctx
->Array
.Objects
);