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
56 update_array(GLcontext
*ctx
, struct gl_client_array
*array
,
57 GLbitfield dirtyBit
, GLsizei elementSize
,
58 GLint size
, GLenum type
, GLenum format
,
59 GLsizei stride
, GLboolean normalized
, const GLvoid
*ptr
)
61 ASSERT(format
== GL_RGBA
|| format
== GL_BGRA
);
63 if (ctx
->Array
.ArrayObj
->VBOonly
&&
64 ctx
->Array
.ArrayBufferObj
->Name
== 0) {
65 /* GL_ARB_vertex_array_object requires that all arrays reside in VBOs.
66 * Generate GL_INVALID_OPERATION if that's not true.
68 _mesa_error(ctx
, GL_INVALID_OPERATION
,
69 "glVertex/Normal/EtcPointer(non-VBO array)");
75 array
->Format
= format
;
76 array
->Stride
= stride
;
77 array
->StrideB
= stride
? stride
: elementSize
;
78 array
->Normalized
= normalized
;
79 array
->Ptr
= (const GLubyte
*) ptr
;
80 array
->_ElementSize
= elementSize
;
82 _mesa_reference_buffer_object(ctx
, &array
->BufferObj
,
83 ctx
->Array
.ArrayBufferObj
);
85 ctx
->NewState
|= _NEW_ARRAY
;
86 ctx
->Array
.NewState
|= dirtyBit
;
91 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
94 GET_CURRENT_CONTEXT(ctx
);
95 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
97 if (size
< 2 || size
> 4) {
98 _mesa_error( ctx
, GL_INVALID_VALUE
, "glVertexPointer(size)" );
102 _mesa_error( ctx
, GL_INVALID_VALUE
, "glVertexPointer(stride)" );
106 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
107 _mesa_debug(ctx
, "glVertexPointer( sz %d type %s stride %d )\n", size
,
108 _mesa_lookup_enum_by_nr( type
), stride
);
110 /* always need to check that <type> is legal */
113 elementSize
= size
* sizeof(GLshort
);
116 elementSize
= size
* sizeof(GLint
);
119 elementSize
= size
* sizeof(GLfloat
);
122 elementSize
= size
* sizeof(GLdouble
);
125 elementSize
= size
* sizeof(GLhalfARB
);
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 update_array(ctx
, &ctx
->Array
.ArrayObj
->Vertex
, _NEW_ARRAY_VERTEX
,
144 elementSize
, size
, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
);
149 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
152 GET_CURRENT_CONTEXT(ctx
);
153 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
156 _mesa_error( ctx
, GL_INVALID_VALUE
, "glNormalPointer(stride)" );
160 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
161 _mesa_debug(ctx
, "glNormalPointer( type %s stride %d )\n",
162 _mesa_lookup_enum_by_nr( type
), stride
);
166 elementSize
= 3 * sizeof(GLbyte
);
169 elementSize
= 3 * sizeof(GLshort
);
172 elementSize
= 3 * sizeof(GLint
);
175 elementSize
= 3 * sizeof(GLfloat
);
178 elementSize
= 3 * sizeof(GLdouble
);
181 elementSize
= 3 * sizeof(GLhalfARB
);
185 elementSize
= 3 * sizeof(GLfixed
);
189 _mesa_error( ctx
, GL_INVALID_ENUM
, "glNormalPointer(type=%s)",
190 _mesa_lookup_enum_by_nr(type
));
194 update_array(ctx
, &ctx
->Array
.ArrayObj
->Normal
, _NEW_ARRAY_NORMAL
,
195 elementSize
, 3, type
, GL_RGBA
, stride
, GL_TRUE
, ptr
);
200 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
204 GET_CURRENT_CONTEXT(ctx
);
205 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
207 if (size
< 3 || size
> 4) {
208 if (!ctx
->Extensions
.EXT_vertex_array_bgra
|| size
!= GL_BGRA
) {
209 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorPointer(size)");
214 _mesa_error( ctx
, GL_INVALID_VALUE
, "glColorPointer(stride)" );
218 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
219 _mesa_debug(ctx
, "glColorPointer( sz %d type %s stride %d )\n", size
,
220 _mesa_lookup_enum_by_nr( type
), stride
);
222 if (size
== GL_BGRA
) {
223 if (type
!= GL_UNSIGNED_BYTE
) {
224 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorPointer(GL_BGRA/GLubyte)");
236 elementSize
= size
* sizeof(GLbyte
);
238 case GL_UNSIGNED_BYTE
:
239 elementSize
= size
* sizeof(GLubyte
);
242 elementSize
= size
* sizeof(GLshort
);
244 case GL_UNSIGNED_SHORT
:
245 elementSize
= size
* sizeof(GLushort
);
248 elementSize
= size
* sizeof(GLint
);
250 case GL_UNSIGNED_INT
:
251 elementSize
= size
* sizeof(GLuint
);
254 elementSize
= size
* sizeof(GLfloat
);
257 elementSize
= size
* sizeof(GLdouble
);
260 elementSize
= size
* sizeof(GLhalfARB
);
264 elementSize
= size
* sizeof(GLfixed
);
268 _mesa_error( ctx
, GL_INVALID_ENUM
, "glColorPointer(type=%s)",
269 _mesa_lookup_enum_by_nr(type
));
273 update_array(ctx
, &ctx
->Array
.ArrayObj
->Color
, _NEW_ARRAY_COLOR0
,
274 elementSize
, size
, type
, format
, stride
, GL_TRUE
, ptr
);
279 _mesa_FogCoordPointerEXT(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
282 GET_CURRENT_CONTEXT(ctx
);
283 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
286 _mesa_error( ctx
, GL_INVALID_VALUE
, "glFogCoordPointer(stride)" );
292 elementSize
= sizeof(GLfloat
);
295 elementSize
= sizeof(GLdouble
);
298 elementSize
= sizeof(GLhalfARB
);
301 _mesa_error( ctx
, GL_INVALID_ENUM
, "glFogCoordPointer(type)" );
305 update_array(ctx
, &ctx
->Array
.ArrayObj
->FogCoord
, _NEW_ARRAY_FOGCOORD
,
306 elementSize
, 1, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
);
311 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
314 GET_CURRENT_CONTEXT(ctx
);
315 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
318 _mesa_error( ctx
, GL_INVALID_VALUE
, "glIndexPointer(stride)" );
323 case GL_UNSIGNED_BYTE
:
324 elementSize
= sizeof(GLubyte
);
327 elementSize
= sizeof(GLshort
);
330 elementSize
= sizeof(GLint
);
333 elementSize
= sizeof(GLfloat
);
336 elementSize
= sizeof(GLdouble
);
339 _mesa_error( ctx
, GL_INVALID_ENUM
, "glIndexPointer(type)" );
343 update_array(ctx
, &ctx
->Array
.ArrayObj
->Index
, _NEW_ARRAY_INDEX
,
344 elementSize
, 1, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
);
349 _mesa_SecondaryColorPointerEXT(GLint size
, GLenum type
,
350 GLsizei stride
, const GLvoid
*ptr
)
354 GET_CURRENT_CONTEXT(ctx
);
355 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
357 if (size
!= 3 && size
!= 4) {
358 if (!ctx
->Extensions
.EXT_vertex_array_bgra
|| size
!= GL_BGRA
) {
359 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSecondaryColorPointer(size)");
364 _mesa_error( ctx
, GL_INVALID_VALUE
, "glSecondaryColorPointer(stride)" );
368 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
369 _mesa_debug(ctx
, "glSecondaryColorPointer( sz %d type %s stride %d )\n",
370 size
, _mesa_lookup_enum_by_nr( type
), stride
);
372 if (size
== GL_BGRA
) {
373 if (type
!= GL_UNSIGNED_BYTE
) {
374 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorPointer(GL_BGRA/GLubyte)");
386 elementSize
= size
* sizeof(GLbyte
);
388 case GL_UNSIGNED_BYTE
:
389 elementSize
= size
* sizeof(GLubyte
);
392 elementSize
= size
* sizeof(GLshort
);
394 case GL_UNSIGNED_SHORT
:
395 elementSize
= size
* sizeof(GLushort
);
398 elementSize
= size
* sizeof(GLint
);
400 case GL_UNSIGNED_INT
:
401 elementSize
= size
* sizeof(GLuint
);
404 elementSize
= size
* sizeof(GLfloat
);
407 elementSize
= size
* sizeof(GLdouble
);
410 elementSize
= size
* sizeof(GLhalfARB
);
413 _mesa_error( ctx
, GL_INVALID_ENUM
, "glSecondaryColorPointer(type=%s)",
414 _mesa_lookup_enum_by_nr(type
));
418 update_array(ctx
, &ctx
->Array
.ArrayObj
->SecondaryColor
, _NEW_ARRAY_COLOR1
,
419 elementSize
, size
, type
, format
, stride
, GL_TRUE
, ptr
);
424 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
428 GET_CURRENT_CONTEXT(ctx
);
429 const GLuint unit
= ctx
->Array
.ActiveTexture
;
430 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
432 if (size
< 1 || size
> 4) {
433 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexCoordPointer(size)" );
437 _mesa_error( ctx
, GL_INVALID_VALUE
, "glTexCoordPointer(stride)" );
441 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
442 _mesa_debug(ctx
, "glTexCoordPointer(unit %u sz %d type %s stride %d)\n",
443 unit
, size
, _mesa_lookup_enum_by_nr( type
), stride
);
445 /* always need to check that <type> is legal */
448 elementSize
= size
* sizeof(GLshort
);
451 elementSize
= size
* sizeof(GLint
);
454 elementSize
= size
* sizeof(GLfloat
);
457 elementSize
= size
* sizeof(GLdouble
);
460 elementSize
= size
* sizeof(GLhalfARB
);
464 elementSize
= size
* sizeof(GLfixed
);
467 #if FEATURE_vertex_array_byte
469 elementSize
= size
* sizeof(GLbyte
);
473 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexCoordPointer(type=%s)",
474 _mesa_lookup_enum_by_nr(type
));
478 update_array(ctx
, &ctx
->Array
.ArrayObj
->TexCoord
[unit
],
479 _NEW_ARRAY_TEXCOORD(unit
),
480 elementSize
, size
, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
);
485 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
487 GET_CURRENT_CONTEXT(ctx
);
488 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
491 _mesa_error( ctx
, GL_INVALID_VALUE
, "glEdgeFlagPointer(stride)" );
495 update_array(ctx
, &ctx
->Array
.ArrayObj
->EdgeFlag
, _NEW_ARRAY_EDGEFLAG
,
496 sizeof(GLboolean
), 1, GL_UNSIGNED_BYTE
, GL_RGBA
,
497 stride
, GL_FALSE
, ptr
);
502 _mesa_PointSizePointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
505 GET_CURRENT_CONTEXT(ctx
);
506 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
509 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPointSizePointer(stride)" );
515 elementSize
= sizeof(GLfloat
);
519 elementSize
= sizeof(GLfixed
);
523 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPointSizePointer(type)" );
527 update_array(ctx
, &ctx
->Array
.ArrayObj
->PointSize
, _NEW_ARRAY_POINT_SIZE
,
528 elementSize
, 1, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
);
532 #if FEATURE_NV_vertex_program
534 * Set a vertex attribute array.
535 * Note that these arrays DO alias the conventional GL vertex arrays
536 * (position, normal, color, fog, texcoord, etc).
537 * The generic attribute slots at #16 and above are not touched.
540 _mesa_VertexAttribPointerNV(GLuint index
, GLint size
, GLenum type
,
541 GLsizei stride
, const GLvoid
*ptr
)
543 GLboolean normalized
= GL_FALSE
;
546 GET_CURRENT_CONTEXT(ctx
);
547 ASSERT_OUTSIDE_BEGIN_END(ctx
);
549 if (index
>= MAX_NV_VERTEX_PROGRAM_INPUTS
) {
550 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(index)");
554 if (size
< 1 || size
> 4) {
555 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(size)");
560 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(stride)");
564 if (type
== GL_UNSIGNED_BYTE
&& size
!= 4) {
565 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(size!=4)");
569 if (size
== GL_BGRA
) {
570 if (type
!= GL_UNSIGNED_BYTE
) {
571 _mesa_error(ctx
, GL_INVALID_VALUE
,
572 "glVertexAttribPointerNV(GL_BGRA/type)");
578 normalized
= GL_TRUE
;
584 /* check for valid 'type' and compute StrideB right away */
586 case GL_UNSIGNED_BYTE
:
587 normalized
= GL_TRUE
;
588 elementSize
= size
* sizeof(GLubyte
);
591 elementSize
= size
* sizeof(GLshort
);
594 elementSize
= size
* sizeof(GLfloat
);
597 elementSize
= size
* sizeof(GLdouble
);
600 _mesa_error( ctx
, GL_INVALID_ENUM
, "glVertexAttribPointerNV(type=%s)",
601 _mesa_lookup_enum_by_nr(type
));
605 update_array(ctx
, &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
606 _NEW_ARRAY_ATTRIB(index
),
607 elementSize
, size
, type
, format
, stride
, normalized
, ptr
);
612 #if FEATURE_ARB_vertex_program
614 * Set a generic vertex attribute array.
615 * Note that these arrays DO NOT alias the conventional GL vertex arrays
616 * (position, normal, color, fog, texcoord, etc).
619 _mesa_VertexAttribPointerARB(GLuint index
, GLint size
, GLenum type
,
620 GLboolean normalized
,
621 GLsizei stride
, const GLvoid
*ptr
)
625 GET_CURRENT_CONTEXT(ctx
);
626 ASSERT_OUTSIDE_BEGIN_END(ctx
);
628 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
629 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
633 if (size
< 1 || size
> 4) {
634 if (!ctx
->Extensions
.EXT_vertex_array_bgra
|| size
!= GL_BGRA
) {
635 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(size)");
641 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(stride)");
645 if (size
== GL_BGRA
) {
646 if (type
!= GL_UNSIGNED_BYTE
) {
647 _mesa_error(ctx
, GL_INVALID_VALUE
,
648 "glVertexAttribPointerARB(GL_BGRA/type)");
651 if (normalized
!= GL_TRUE
) {
652 _mesa_error(ctx
, GL_INVALID_VALUE
,
653 "glVertexAttribPointerARB(GL_BGRA/normalized)");
664 /* check for valid 'type' and compute StrideB right away */
665 /* NOTE: more types are supported here than in the NV extension */
668 elementSize
= size
* sizeof(GLbyte
);
670 case GL_UNSIGNED_BYTE
:
671 elementSize
= size
* sizeof(GLubyte
);
674 elementSize
= size
* sizeof(GLshort
);
676 case GL_UNSIGNED_SHORT
:
677 elementSize
= size
* sizeof(GLushort
);
680 elementSize
= size
* sizeof(GLint
);
682 case GL_UNSIGNED_INT
:
683 elementSize
= size
* sizeof(GLuint
);
686 elementSize
= size
* sizeof(GLfloat
);
689 elementSize
= size
* sizeof(GLdouble
);
692 elementSize
= size
* sizeof(GLhalfARB
);
696 elementSize
= size
* sizeof(GLfixed
);
700 _mesa_error( ctx
, GL_INVALID_ENUM
, "glVertexAttribPointerARB(type)" );
704 update_array(ctx
, &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
705 _NEW_ARRAY_ATTRIB(index
),
706 elementSize
, size
, type
, format
, stride
, normalized
, ptr
);
712 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
713 GLsizei count
, const GLvoid
*ptr
)
716 _mesa_VertexPointer(size
, type
, stride
, ptr
);
721 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
725 _mesa_NormalPointer(type
, stride
, ptr
);
730 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
734 _mesa_ColorPointer(size
, type
, stride
, ptr
);
739 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
743 _mesa_IndexPointer(type
, stride
, ptr
);
748 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
749 GLsizei count
, const GLvoid
*ptr
)
752 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
757 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
760 _mesa_EdgeFlagPointer(stride
, ptr
);
765 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
767 GET_CURRENT_CONTEXT(ctx
);
768 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
769 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
770 GLenum ctype
= 0; /* color type */
771 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
772 const GLint toffset
= 0; /* always zero */
773 GLint defstride
; /* default stride */
776 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
779 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
782 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
788 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
789 tcomps
= 0; ccomps
= 0; vcomps
= 2;
794 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
795 tcomps
= 0; ccomps
= 0; vcomps
= 3;
800 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
801 tcomps
= 0; ccomps
= 4; vcomps
= 2;
802 ctype
= GL_UNSIGNED_BYTE
;
808 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
809 tcomps
= 0; ccomps
= 4; vcomps
= 3;
810 ctype
= GL_UNSIGNED_BYTE
;
816 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
817 tcomps
= 0; ccomps
= 3; vcomps
= 3;
824 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
825 tcomps
= 0; ccomps
= 0; vcomps
= 3;
831 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
832 tcomps
= 0; ccomps
= 4; vcomps
= 3;
840 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
841 tcomps
= 2; ccomps
= 0; vcomps
= 3;
846 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
847 tcomps
= 4; ccomps
= 0; vcomps
= 4;
851 case GL_T2F_C4UB_V3F
:
852 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
853 tcomps
= 2; ccomps
= 4; vcomps
= 3;
854 ctype
= GL_UNSIGNED_BYTE
;
860 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
861 tcomps
= 2; ccomps
= 3; vcomps
= 3;
868 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
869 tcomps
= 2; ccomps
= 0; vcomps
= 3;
874 case GL_T2F_C4F_N3F_V3F
:
875 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
876 tcomps
= 2; ccomps
= 4; vcomps
= 3;
883 case GL_T4F_C4F_N3F_V4F
:
884 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
885 tcomps
= 4; ccomps
= 4; vcomps
= 4;
893 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
901 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
902 _mesa_DisableClientState( GL_INDEX_ARRAY
);
903 /* XXX also disable secondary color and generic arrays? */
907 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
908 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
909 (GLubyte
*) pointer
+ toffset
);
912 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
917 _mesa_EnableClientState( GL_COLOR_ARRAY
);
918 _mesa_ColorPointer( ccomps
, ctype
, stride
,
919 (GLubyte
*) pointer
+ coffset
);
922 _mesa_DisableClientState( GL_COLOR_ARRAY
);
928 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
929 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
932 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
936 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
937 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
938 (GLubyte
*) pointer
+ voffset
);
943 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
945 GET_CURRENT_CONTEXT(ctx
);
946 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
948 if (MESA_VERBOSE
& VERBOSE_API
)
949 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
952 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
956 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
959 if (ctx
->Array
.LockCount
!= 0) {
960 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
964 ctx
->Array
.LockFirst
= first
;
965 ctx
->Array
.LockCount
= count
;
967 ctx
->NewState
|= _NEW_ARRAY
;
968 ctx
->Array
.NewState
|= _NEW_ARRAY_ALL
;
973 _mesa_UnlockArraysEXT( void )
975 GET_CURRENT_CONTEXT(ctx
);
976 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
978 if (MESA_VERBOSE
& VERBOSE_API
)
979 _mesa_debug(ctx
, "glUnlockArrays\n");
981 if (ctx
->Array
.LockCount
== 0) {
982 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
986 ctx
->Array
.LockFirst
= 0;
987 ctx
->Array
.LockCount
= 0;
988 ctx
->NewState
|= _NEW_ARRAY
;
989 ctx
->Array
.NewState
|= _NEW_ARRAY_ALL
;
993 /* GL_EXT_multi_draw_arrays */
994 /* Somebody forgot to spec the first and count parameters as const! <sigh> */
996 _mesa_MultiDrawArraysEXT( GLenum mode
, GLint
*first
,
997 GLsizei
*count
, GLsizei primcount
)
999 GET_CURRENT_CONTEXT(ctx
);
1002 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1004 for (i
= 0; i
< primcount
; i
++) {
1006 CALL_DrawArrays(ctx
->Exec
, (mode
, first
[i
], count
[i
]));
1012 /* GL_IBM_multimode_draw_arrays */
1014 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1015 const GLsizei
* count
,
1016 GLsizei primcount
, GLint modestride
)
1018 GET_CURRENT_CONTEXT(ctx
);
1021 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1023 for ( i
= 0 ; i
< primcount
; i
++ ) {
1024 if ( count
[i
] > 0 ) {
1025 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1026 CALL_DrawArrays(ctx
->Exec
, ( m
, first
[i
], count
[i
] ));
1032 /* GL_IBM_multimode_draw_arrays */
1034 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1035 GLenum type
, const GLvoid
* const * indices
,
1036 GLsizei primcount
, GLint modestride
)
1038 GET_CURRENT_CONTEXT(ctx
);
1041 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1043 /* XXX not sure about ARB_vertex_buffer_object handling here */
1045 for ( i
= 0 ; i
< primcount
; i
++ ) {
1046 if ( count
[i
] > 0 ) {
1047 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1048 CALL_DrawElements(ctx
->Exec
, ( m
, count
[i
], type
, indices
[i
] ));
1055 * Copy one client vertex array to another.
1058 _mesa_copy_client_array(GLcontext
*ctx
,
1059 struct gl_client_array
*dst
,
1060 struct gl_client_array
*src
)
1062 dst
->Size
= src
->Size
;
1063 dst
->Type
= src
->Type
;
1064 dst
->Format
= src
->Format
;
1065 dst
->Stride
= src
->Stride
;
1066 dst
->StrideB
= src
->StrideB
;
1067 dst
->Ptr
= src
->Ptr
;
1068 dst
->Enabled
= src
->Enabled
;
1069 dst
->Normalized
= src
->Normalized
;
1070 dst
->_ElementSize
= src
->_ElementSize
;
1071 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1072 dst
->_MaxElement
= src
->_MaxElement
;
1078 * Print vertex array's fields.
1081 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1084 _mesa_printf(" %s[%d]: ", name
, index
);
1086 _mesa_printf(" %s: ", name
);
1087 _mesa_printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %u), MaxElem=%u\n",
1088 array
->Ptr
, array
->Type
, array
->Size
,
1089 array
->_ElementSize
, array
->StrideB
,
1090 array
->BufferObj
->Name
, array
->BufferObj
->Size
,
1091 array
->_MaxElement
);
1096 * Print current vertex object/array info. For debug.
1099 _mesa_print_arrays(GLcontext
*ctx
)
1101 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
1104 _mesa_update_array_object_max_element(ctx
, arrayObj
);
1106 _mesa_printf("Array Object %u\n", arrayObj
->Name
);
1107 if (arrayObj
->Vertex
.Enabled
)
1108 print_array("Vertex", -1, &arrayObj
->Vertex
);
1109 if (arrayObj
->Normal
.Enabled
)
1110 print_array("Normal", -1, &arrayObj
->Normal
);
1111 if (arrayObj
->Color
.Enabled
)
1112 print_array("Color", -1, &arrayObj
->Color
);
1113 for (i
= 0; i
< Elements(arrayObj
->TexCoord
); i
++)
1114 if (arrayObj
->TexCoord
[i
].Enabled
)
1115 print_array("TexCoord", i
, &arrayObj
->TexCoord
[i
]);
1116 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++)
1117 if (arrayObj
->VertexAttrib
[i
].Enabled
)
1118 print_array("Attrib", i
, &arrayObj
->VertexAttrib
[i
]);
1119 _mesa_printf(" _MaxElement = %u\n", arrayObj
->_MaxElement
);
1124 * Initialize vertex array state for given context.
1127 _mesa_init_varray(GLcontext
*ctx
)
1129 ctx
->Array
.DefaultArrayObj
= _mesa_new_array_object(ctx
, 0);
1130 _mesa_reference_array_object(ctx
, &ctx
->Array
.ArrayObj
,
1131 ctx
->Array
.DefaultArrayObj
);
1132 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1134 ctx
->Array
.Objects
= _mesa_NewHashTable();
1139 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1142 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1144 struct gl_array_object
*arrayObj
= (struct gl_array_object
*) data
;
1145 GLcontext
*ctx
= (GLcontext
*) userData
;
1146 _mesa_delete_array_object(ctx
, arrayObj
);
1151 * Free vertex array state for given context.
1154 _mesa_free_varray_data(GLcontext
*ctx
)
1156 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1157 _mesa_DeleteHashTable(ctx
->Array
.Objects
);