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
);
126 elementSize
= size
* sizeof(GLfixed
);
129 #if FEATURE_vertex_array_byte
131 elementSize
= size
* sizeof(GLbyte
);
135 _mesa_error( ctx
, GL_INVALID_ENUM
, "glVertexPointer(type=%s)",
136 _mesa_lookup_enum_by_nr(type
));
140 update_array(ctx
, &ctx
->Array
.ArrayObj
->Vertex
, _NEW_ARRAY_VERTEX
,
141 elementSize
, size
, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
);
146 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
149 GET_CURRENT_CONTEXT(ctx
);
150 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
153 _mesa_error( ctx
, GL_INVALID_VALUE
, "glNormalPointer(stride)" );
157 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
158 _mesa_debug(ctx
, "glNormalPointer( type %s stride %d )\n",
159 _mesa_lookup_enum_by_nr( type
), stride
);
163 elementSize
= 3 * sizeof(GLbyte
);
166 elementSize
= 3 * sizeof(GLshort
);
169 elementSize
= 3 * sizeof(GLint
);
172 elementSize
= 3 * sizeof(GLfloat
);
175 elementSize
= 3 * sizeof(GLdouble
);
179 elementSize
= 3 * sizeof(GLfixed
);
183 _mesa_error( ctx
, GL_INVALID_ENUM
, "glNormalPointer(type=%s)",
184 _mesa_lookup_enum_by_nr(type
));
188 update_array(ctx
, &ctx
->Array
.ArrayObj
->Normal
, _NEW_ARRAY_NORMAL
,
189 elementSize
, 3, type
, GL_RGBA
, stride
, GL_TRUE
, ptr
);
194 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
198 GET_CURRENT_CONTEXT(ctx
);
199 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
201 if (size
< 3 || size
> 4) {
202 if (!ctx
->Extensions
.EXT_vertex_array_bgra
|| size
!= GL_BGRA
) {
203 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorPointer(size)");
208 _mesa_error( ctx
, GL_INVALID_VALUE
, "glColorPointer(stride)" );
212 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
213 _mesa_debug(ctx
, "glColorPointer( sz %d type %s stride %d )\n", size
,
214 _mesa_lookup_enum_by_nr( type
), stride
);
216 if (size
== GL_BGRA
) {
217 if (type
!= GL_UNSIGNED_BYTE
) {
218 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorPointer(GL_BGRA/GLubyte)");
230 elementSize
= size
* sizeof(GLbyte
);
232 case GL_UNSIGNED_BYTE
:
233 elementSize
= size
* sizeof(GLubyte
);
236 elementSize
= size
* sizeof(GLshort
);
238 case GL_UNSIGNED_SHORT
:
239 elementSize
= size
* sizeof(GLushort
);
242 elementSize
= size
* sizeof(GLint
);
244 case GL_UNSIGNED_INT
:
245 elementSize
= size
* sizeof(GLuint
);
248 elementSize
= size
* sizeof(GLfloat
);
251 elementSize
= size
* sizeof(GLdouble
);
255 elementSize
= size
* sizeof(GLfixed
);
259 _mesa_error( ctx
, GL_INVALID_ENUM
, "glColorPointer(type=%s)",
260 _mesa_lookup_enum_by_nr(type
));
264 update_array(ctx
, &ctx
->Array
.ArrayObj
->Color
, _NEW_ARRAY_COLOR0
,
265 elementSize
, size
, type
, format
, stride
, GL_TRUE
, ptr
);
270 _mesa_FogCoordPointerEXT(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
273 GET_CURRENT_CONTEXT(ctx
);
274 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
277 _mesa_error( ctx
, GL_INVALID_VALUE
, "glFogCoordPointer(stride)" );
283 elementSize
= sizeof(GLfloat
);
286 elementSize
= sizeof(GLdouble
);
289 _mesa_error( ctx
, GL_INVALID_ENUM
, "glFogCoordPointer(type)" );
293 update_array(ctx
, &ctx
->Array
.ArrayObj
->FogCoord
, _NEW_ARRAY_FOGCOORD
,
294 elementSize
, 1, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
);
299 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
302 GET_CURRENT_CONTEXT(ctx
);
303 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
306 _mesa_error( ctx
, GL_INVALID_VALUE
, "glIndexPointer(stride)" );
311 case GL_UNSIGNED_BYTE
:
312 elementSize
= sizeof(GLubyte
);
315 elementSize
= sizeof(GLshort
);
318 elementSize
= sizeof(GLint
);
321 elementSize
= sizeof(GLfloat
);
324 elementSize
= sizeof(GLdouble
);
327 _mesa_error( ctx
, GL_INVALID_ENUM
, "glIndexPointer(type)" );
331 update_array(ctx
, &ctx
->Array
.ArrayObj
->Index
, _NEW_ARRAY_INDEX
,
332 elementSize
, 1, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
);
337 _mesa_SecondaryColorPointerEXT(GLint size
, GLenum type
,
338 GLsizei stride
, const GLvoid
*ptr
)
342 GET_CURRENT_CONTEXT(ctx
);
343 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
345 if (size
!= 3 && size
!= 4) {
346 if (!ctx
->Extensions
.EXT_vertex_array_bgra
|| size
!= GL_BGRA
) {
347 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSecondaryColorPointer(size)");
352 _mesa_error( ctx
, GL_INVALID_VALUE
, "glSecondaryColorPointer(stride)" );
356 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
357 _mesa_debug(ctx
, "glSecondaryColorPointer( sz %d type %s stride %d )\n",
358 size
, _mesa_lookup_enum_by_nr( type
), stride
);
360 if (size
== GL_BGRA
) {
361 if (type
!= GL_UNSIGNED_BYTE
) {
362 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorPointer(GL_BGRA/GLubyte)");
374 elementSize
= size
* sizeof(GLbyte
);
376 case GL_UNSIGNED_BYTE
:
377 elementSize
= size
* sizeof(GLubyte
);
380 elementSize
= size
* sizeof(GLshort
);
382 case GL_UNSIGNED_SHORT
:
383 elementSize
= size
* sizeof(GLushort
);
386 elementSize
= size
* sizeof(GLint
);
388 case GL_UNSIGNED_INT
:
389 elementSize
= size
* sizeof(GLuint
);
392 elementSize
= size
* sizeof(GLfloat
);
395 elementSize
= size
* sizeof(GLdouble
);
398 _mesa_error( ctx
, GL_INVALID_ENUM
, "glSecondaryColorPointer(type=%s)",
399 _mesa_lookup_enum_by_nr(type
));
403 update_array(ctx
, &ctx
->Array
.ArrayObj
->SecondaryColor
, _NEW_ARRAY_COLOR1
,
404 elementSize
, size
, type
, format
, stride
, GL_TRUE
, 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=%s)",
456 _mesa_lookup_enum_by_nr(type
));
460 update_array(ctx
, &ctx
->Array
.ArrayObj
->TexCoord
[unit
],
461 _NEW_ARRAY_TEXCOORD(unit
),
462 elementSize
, size
, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
);
467 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
469 GET_CURRENT_CONTEXT(ctx
);
470 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
473 _mesa_error( ctx
, GL_INVALID_VALUE
, "glEdgeFlagPointer(stride)" );
477 update_array(ctx
, &ctx
->Array
.ArrayObj
->EdgeFlag
, _NEW_ARRAY_EDGEFLAG
,
478 sizeof(GLboolean
), 1, GL_UNSIGNED_BYTE
, GL_RGBA
,
479 stride
, GL_FALSE
, ptr
);
484 _mesa_PointSizePointer(GLenum type
, 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
, "glPointSizePointer(stride)" );
497 elementSize
= sizeof(GLfloat
);
501 elementSize
= sizeof(GLfixed
);
505 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPointSizePointer(type)" );
509 update_array(ctx
, &ctx
->Array
.ArrayObj
->PointSize
, _NEW_ARRAY_POINT_SIZE
,
510 elementSize
, 1, type
, GL_RGBA
, stride
, GL_FALSE
, ptr
);
514 #if FEATURE_NV_vertex_program
516 * Set a vertex attribute array.
517 * Note that these arrays DO alias the conventional GL vertex arrays
518 * (position, normal, color, fog, texcoord, etc).
519 * The generic attribute slots at #16 and above are not touched.
522 _mesa_VertexAttribPointerNV(GLuint index
, GLint size
, GLenum type
,
523 GLsizei stride
, const GLvoid
*ptr
)
525 GLboolean normalized
= GL_FALSE
;
528 GET_CURRENT_CONTEXT(ctx
);
529 ASSERT_OUTSIDE_BEGIN_END(ctx
);
531 if (index
>= MAX_NV_VERTEX_PROGRAM_INPUTS
) {
532 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(index)");
536 if (size
< 1 || size
> 4) {
537 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(size)");
542 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(stride)");
546 if (type
== GL_UNSIGNED_BYTE
&& size
!= 4) {
547 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(size!=4)");
551 if (size
== GL_BGRA
) {
552 if (type
!= GL_UNSIGNED_BYTE
) {
553 _mesa_error(ctx
, GL_INVALID_VALUE
,
554 "glVertexAttribPointerNV(GL_BGRA/type)");
560 normalized
= GL_TRUE
;
566 /* check for valid 'type' and compute StrideB right away */
568 case GL_UNSIGNED_BYTE
:
569 normalized
= GL_TRUE
;
570 elementSize
= size
* sizeof(GLubyte
);
573 elementSize
= size
* sizeof(GLshort
);
576 elementSize
= size
* sizeof(GLfloat
);
579 elementSize
= size
* sizeof(GLdouble
);
582 _mesa_error( ctx
, GL_INVALID_ENUM
, "glVertexAttribPointerNV(type=%s)",
583 _mesa_lookup_enum_by_nr(type
));
587 update_array(ctx
, &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
588 _NEW_ARRAY_ATTRIB(index
),
589 elementSize
, size
, type
, format
, stride
, normalized
, ptr
);
594 #if FEATURE_ARB_vertex_program
596 * Set a generic vertex attribute array.
597 * Note that these arrays DO NOT alias the conventional GL vertex arrays
598 * (position, normal, color, fog, texcoord, etc).
601 _mesa_VertexAttribPointerARB(GLuint index
, GLint size
, GLenum type
,
602 GLboolean normalized
,
603 GLsizei stride
, const GLvoid
*ptr
)
607 GET_CURRENT_CONTEXT(ctx
);
608 ASSERT_OUTSIDE_BEGIN_END(ctx
);
610 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
611 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
615 if (size
< 1 || size
> 4) {
616 if (!ctx
->Extensions
.EXT_vertex_array_bgra
|| size
!= GL_BGRA
) {
617 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(size)");
623 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(stride)");
627 if (size
== GL_BGRA
) {
628 if (type
!= GL_UNSIGNED_BYTE
) {
629 _mesa_error(ctx
, GL_INVALID_VALUE
,
630 "glVertexAttribPointerARB(GL_BGRA/type)");
633 if (normalized
!= GL_TRUE
) {
634 _mesa_error(ctx
, GL_INVALID_VALUE
,
635 "glVertexAttribPointerARB(GL_BGRA/normalized)");
646 /* check for valid 'type' and compute StrideB right away */
647 /* NOTE: more types are supported here than in the NV extension */
650 elementSize
= size
* sizeof(GLbyte
);
652 case GL_UNSIGNED_BYTE
:
653 elementSize
= size
* sizeof(GLubyte
);
656 elementSize
= size
* sizeof(GLshort
);
658 case GL_UNSIGNED_SHORT
:
659 elementSize
= size
* sizeof(GLushort
);
662 elementSize
= size
* sizeof(GLint
);
664 case GL_UNSIGNED_INT
:
665 elementSize
= size
* sizeof(GLuint
);
668 elementSize
= size
* sizeof(GLfloat
);
671 elementSize
= size
* sizeof(GLdouble
);
675 elementSize
= size
* sizeof(GLfixed
);
679 _mesa_error( ctx
, GL_INVALID_ENUM
, "glVertexAttribPointerARB(type)" );
683 update_array(ctx
, &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
684 _NEW_ARRAY_ATTRIB(index
),
685 elementSize
, size
, type
, format
, stride
, normalized
, ptr
);
691 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
692 GLsizei count
, const GLvoid
*ptr
)
695 _mesa_VertexPointer(size
, type
, stride
, ptr
);
700 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
704 _mesa_NormalPointer(type
, stride
, ptr
);
709 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
713 _mesa_ColorPointer(size
, type
, stride
, ptr
);
718 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
722 _mesa_IndexPointer(type
, stride
, ptr
);
727 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
728 GLsizei count
, const GLvoid
*ptr
)
731 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
736 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
739 _mesa_EdgeFlagPointer(stride
, ptr
);
744 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
746 GET_CURRENT_CONTEXT(ctx
);
747 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
748 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
749 GLenum ctype
= 0; /* color type */
750 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
751 const GLint toffset
= 0; /* always zero */
752 GLint defstride
; /* default stride */
755 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
758 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
761 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
767 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
768 tcomps
= 0; ccomps
= 0; vcomps
= 2;
773 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
774 tcomps
= 0; ccomps
= 0; vcomps
= 3;
779 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
780 tcomps
= 0; ccomps
= 4; vcomps
= 2;
781 ctype
= GL_UNSIGNED_BYTE
;
787 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
788 tcomps
= 0; ccomps
= 4; vcomps
= 3;
789 ctype
= GL_UNSIGNED_BYTE
;
795 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
796 tcomps
= 0; ccomps
= 3; vcomps
= 3;
803 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
804 tcomps
= 0; ccomps
= 0; vcomps
= 3;
810 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
811 tcomps
= 0; ccomps
= 4; vcomps
= 3;
819 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
820 tcomps
= 2; ccomps
= 0; vcomps
= 3;
825 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
826 tcomps
= 4; ccomps
= 0; vcomps
= 4;
830 case GL_T2F_C4UB_V3F
:
831 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
832 tcomps
= 2; ccomps
= 4; vcomps
= 3;
833 ctype
= GL_UNSIGNED_BYTE
;
839 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
840 tcomps
= 2; ccomps
= 3; vcomps
= 3;
847 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
848 tcomps
= 2; ccomps
= 0; vcomps
= 3;
853 case GL_T2F_C4F_N3F_V3F
:
854 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
855 tcomps
= 2; ccomps
= 4; vcomps
= 3;
862 case GL_T4F_C4F_N3F_V4F
:
863 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
864 tcomps
= 4; ccomps
= 4; vcomps
= 4;
872 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
880 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
881 _mesa_DisableClientState( GL_INDEX_ARRAY
);
882 /* XXX also disable secondary color and generic arrays? */
886 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
887 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
888 (GLubyte
*) pointer
+ toffset
);
891 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
896 _mesa_EnableClientState( GL_COLOR_ARRAY
);
897 _mesa_ColorPointer( ccomps
, ctype
, stride
,
898 (GLubyte
*) pointer
+ coffset
);
901 _mesa_DisableClientState( GL_COLOR_ARRAY
);
907 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
908 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
911 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
915 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
916 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
917 (GLubyte
*) pointer
+ voffset
);
922 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
924 GET_CURRENT_CONTEXT(ctx
);
925 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
927 if (MESA_VERBOSE
& VERBOSE_API
)
928 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
931 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
935 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
938 if (ctx
->Array
.LockCount
!= 0) {
939 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
943 ctx
->Array
.LockFirst
= first
;
944 ctx
->Array
.LockCount
= count
;
946 ctx
->NewState
|= _NEW_ARRAY
;
947 ctx
->Array
.NewState
|= _NEW_ARRAY_ALL
;
952 _mesa_UnlockArraysEXT( void )
954 GET_CURRENT_CONTEXT(ctx
);
955 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
957 if (MESA_VERBOSE
& VERBOSE_API
)
958 _mesa_debug(ctx
, "glUnlockArrays\n");
960 if (ctx
->Array
.LockCount
== 0) {
961 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
965 ctx
->Array
.LockFirst
= 0;
966 ctx
->Array
.LockCount
= 0;
967 ctx
->NewState
|= _NEW_ARRAY
;
968 ctx
->Array
.NewState
|= _NEW_ARRAY_ALL
;
972 /* GL_EXT_multi_draw_arrays */
973 /* Somebody forgot to spec the first and count parameters as const! <sigh> */
975 _mesa_MultiDrawArraysEXT( GLenum mode
, GLint
*first
,
976 GLsizei
*count
, GLsizei primcount
)
978 GET_CURRENT_CONTEXT(ctx
);
981 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
983 for (i
= 0; i
< primcount
; i
++) {
985 CALL_DrawArrays(ctx
->Exec
, (mode
, first
[i
], count
[i
]));
991 /* GL_IBM_multimode_draw_arrays */
993 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
994 const GLsizei
* count
,
995 GLsizei primcount
, GLint modestride
)
997 GET_CURRENT_CONTEXT(ctx
);
1000 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1002 for ( i
= 0 ; i
< primcount
; i
++ ) {
1003 if ( count
[i
] > 0 ) {
1004 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1005 CALL_DrawArrays(ctx
->Exec
, ( m
, first
[i
], count
[i
] ));
1011 /* GL_IBM_multimode_draw_arrays */
1013 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1014 GLenum type
, const GLvoid
* const * indices
,
1015 GLsizei primcount
, GLint modestride
)
1017 GET_CURRENT_CONTEXT(ctx
);
1020 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1022 /* XXX not sure about ARB_vertex_buffer_object handling here */
1024 for ( i
= 0 ; i
< primcount
; i
++ ) {
1025 if ( count
[i
] > 0 ) {
1026 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1027 CALL_DrawElements(ctx
->Exec
, ( m
, count
[i
], type
, indices
[i
] ));
1034 * Copy one client vertex array to another.
1037 _mesa_copy_client_array(GLcontext
*ctx
,
1038 struct gl_client_array
*dst
,
1039 struct gl_client_array
*src
)
1041 dst
->Size
= src
->Size
;
1042 dst
->Type
= src
->Type
;
1043 dst
->Format
= src
->Format
;
1044 dst
->Stride
= src
->Stride
;
1045 dst
->StrideB
= src
->StrideB
;
1046 dst
->Ptr
= src
->Ptr
;
1047 dst
->Enabled
= src
->Enabled
;
1048 dst
->Normalized
= src
->Normalized
;
1049 dst
->_ElementSize
= src
->_ElementSize
;
1050 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1051 dst
->_MaxElement
= src
->_MaxElement
;
1057 * Print vertex array's fields.
1060 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1063 _mesa_printf(" %s[%d]: ", name
, index
);
1065 _mesa_printf(" %s: ", name
);
1066 _mesa_printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %u), MaxElem=%u\n",
1067 array
->Ptr
, array
->Type
, array
->Size
,
1068 array
->_ElementSize
, array
->StrideB
,
1069 array
->BufferObj
->Name
, array
->BufferObj
->Size
,
1070 array
->_MaxElement
);
1075 * Print current vertex object/array info. For debug.
1078 _mesa_print_arrays(GLcontext
*ctx
)
1080 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
1083 _mesa_update_array_object_max_element(ctx
, arrayObj
);
1085 _mesa_printf("Array Object %u\n", arrayObj
->Name
);
1086 if (arrayObj
->Vertex
.Enabled
)
1087 print_array("Vertex", -1, &arrayObj
->Vertex
);
1088 if (arrayObj
->Normal
.Enabled
)
1089 print_array("Normal", -1, &arrayObj
->Normal
);
1090 if (arrayObj
->Color
.Enabled
)
1091 print_array("Color", -1, &arrayObj
->Color
);
1092 for (i
= 0; i
< Elements(arrayObj
->TexCoord
); i
++)
1093 if (arrayObj
->TexCoord
[i
].Enabled
)
1094 print_array("TexCoord", i
, &arrayObj
->TexCoord
[i
]);
1095 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++)
1096 if (arrayObj
->VertexAttrib
[i
].Enabled
)
1097 print_array("Attrib", i
, &arrayObj
->VertexAttrib
[i
]);
1098 _mesa_printf(" _MaxElement = %u\n", arrayObj
->_MaxElement
);
1103 * Initialize vertex array state for given context.
1106 _mesa_init_varray(GLcontext
*ctx
)
1108 ctx
->Array
.DefaultArrayObj
= _mesa_new_array_object(ctx
, 0);
1109 _mesa_reference_array_object(ctx
, &ctx
->Array
.ArrayObj
,
1110 ctx
->Array
.DefaultArrayObj
);
1111 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1113 ctx
->Array
.Objects
= _mesa_NewHashTable();
1118 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1121 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1123 struct gl_array_object
*arrayObj
= (struct gl_array_object
*) data
;
1124 GLcontext
*ctx
= (GLcontext
*) userData
;
1125 _mesa_delete_array_object(ctx
, arrayObj
);
1130 * Free vertex array state for given context.
1133 _mesa_free_varray_data(GLcontext
*ctx
)
1135 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1136 _mesa_DeleteHashTable(ctx
->Array
.Objects
);