1 /* $Id: varray.c,v 1.22 2000/06/12 15:30:51 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 #include "translate.h"
48 #include "vbindirect.h"
56 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
58 GET_CURRENT_CONTEXT(ctx
);
60 if (size
<2 || size
>4) {
61 gl_error( ctx
, GL_INVALID_VALUE
, "glVertexPointer(size)" );
65 gl_error( ctx
, GL_INVALID_VALUE
, "glVertexPointer(stride)" );
69 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
70 fprintf(stderr
, "glVertexPointer( sz %d type %s stride %d )\n", size
,
71 gl_lookup_enum_by_nr( type
),
74 ctx
->Array
.Vertex
.StrideB
= stride
;
78 ctx
->Array
.Vertex
.StrideB
= size
*sizeof(GLshort
);
81 ctx
->Array
.Vertex
.StrideB
= size
*sizeof(GLint
);
84 ctx
->Array
.Vertex
.StrideB
= size
*sizeof(GLfloat
);
87 ctx
->Array
.Vertex
.StrideB
= size
*sizeof(GLdouble
);
90 gl_error( ctx
, GL_INVALID_ENUM
, "glVertexPointer(type)" );
94 ctx
->Array
.Vertex
.Size
= size
;
95 ctx
->Array
.Vertex
.Type
= type
;
96 ctx
->Array
.Vertex
.Stride
= stride
;
97 ctx
->Array
.Vertex
.Ptr
= (void *) ptr
;
98 ctx
->Array
.VertexFunc
= gl_trans_4f_tab
[size
][TYPE_IDX(type
)];
99 ctx
->Array
.VertexEltFunc
= gl_trans_elt_4f_tab
[size
][TYPE_IDX(type
)];
100 ctx
->Array
.NewArrayState
|= VERT_OBJ_ANY
;
101 ctx
->NewState
|= NEW_CLIENT_STATE
;
108 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
110 GET_CURRENT_CONTEXT(ctx
);
113 gl_error( ctx
, GL_INVALID_VALUE
, "glNormalPointer(stride)" );
117 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
118 fprintf(stderr
, "glNormalPointer( type %s stride %d )\n",
119 gl_lookup_enum_by_nr( type
),
122 ctx
->Array
.Normal
.StrideB
= stride
;
126 ctx
->Array
.Normal
.StrideB
= 3*sizeof(GLbyte
);
129 ctx
->Array
.Normal
.StrideB
= 3*sizeof(GLshort
);
132 ctx
->Array
.Normal
.StrideB
= 3*sizeof(GLint
);
135 ctx
->Array
.Normal
.StrideB
= 3*sizeof(GLfloat
);
138 ctx
->Array
.Normal
.StrideB
= 3*sizeof(GLdouble
);
141 gl_error( ctx
, GL_INVALID_ENUM
, "glNormalPointer(type)" );
145 ctx
->Array
.Normal
.Type
= type
;
146 ctx
->Array
.Normal
.Stride
= stride
;
147 ctx
->Array
.Normal
.Ptr
= (void *) ptr
;
148 ctx
->Array
.NormalFunc
= gl_trans_3f_tab
[TYPE_IDX(type
)];
149 ctx
->Array
.NormalEltFunc
= gl_trans_elt_3f_tab
[TYPE_IDX(type
)];
150 ctx
->Array
.NewArrayState
|= VERT_NORM
;
151 ctx
->NewState
|= NEW_CLIENT_STATE
;
157 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
159 GET_CURRENT_CONTEXT(ctx
);
161 if (size
<3 || size
>4) {
162 gl_error( ctx
, GL_INVALID_VALUE
, "glColorPointer(size)" );
166 gl_error( ctx
, GL_INVALID_VALUE
, "glColorPointer(stride)" );
170 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
171 fprintf(stderr
, "glColorPointer( sz %d type %s stride %d )\n", size
,
172 gl_lookup_enum_by_nr( type
),
175 ctx
->Array
.Color
.StrideB
= stride
;
179 ctx
->Array
.Color
.StrideB
= size
*sizeof(GLbyte
);
181 case GL_UNSIGNED_BYTE
:
182 ctx
->Array
.Color
.StrideB
= size
*sizeof(GLubyte
);
185 ctx
->Array
.Color
.StrideB
= size
*sizeof(GLshort
);
187 case GL_UNSIGNED_SHORT
:
188 ctx
->Array
.Color
.StrideB
= size
*sizeof(GLushort
);
191 ctx
->Array
.Color
.StrideB
= size
*sizeof(GLint
);
193 case GL_UNSIGNED_INT
:
194 ctx
->Array
.Color
.StrideB
= size
*sizeof(GLuint
);
197 ctx
->Array
.Color
.StrideB
= size
*sizeof(GLfloat
);
200 ctx
->Array
.Color
.StrideB
= size
*sizeof(GLdouble
);
203 gl_error( ctx
, GL_INVALID_ENUM
, "glColorPointer(type)" );
207 ctx
->Array
.Color
.Size
= size
;
208 ctx
->Array
.Color
.Type
= type
;
209 ctx
->Array
.Color
.Stride
= stride
;
210 ctx
->Array
.Color
.Ptr
= (void *) ptr
;
211 ctx
->Array
.ColorFunc
= gl_trans_4ub_tab
[size
][TYPE_IDX(type
)];
212 ctx
->Array
.ColorEltFunc
= gl_trans_elt_4ub_tab
[size
][TYPE_IDX(type
)];
213 ctx
->Array
.NewArrayState
|= VERT_RGBA
;
214 ctx
->NewState
|= NEW_CLIENT_STATE
;
220 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
222 GET_CURRENT_CONTEXT(ctx
);
225 gl_error( ctx
, GL_INVALID_VALUE
, "glIndexPointer(stride)" );
229 ctx
->Array
.Index
.StrideB
= stride
;
232 case GL_UNSIGNED_BYTE
:
233 ctx
->Array
.Index
.StrideB
= sizeof(GLubyte
);
236 ctx
->Array
.Index
.StrideB
= sizeof(GLshort
);
239 ctx
->Array
.Index
.StrideB
= sizeof(GLint
);
242 ctx
->Array
.Index
.StrideB
= sizeof(GLfloat
);
245 ctx
->Array
.Index
.StrideB
= sizeof(GLdouble
);
248 gl_error( ctx
, GL_INVALID_ENUM
, "glIndexPointer(type)" );
252 ctx
->Array
.Index
.Type
= type
;
253 ctx
->Array
.Index
.Stride
= stride
;
254 ctx
->Array
.Index
.Ptr
= (void *) ptr
;
255 ctx
->Array
.IndexFunc
= gl_trans_1ui_tab
[TYPE_IDX(type
)];
256 ctx
->Array
.IndexEltFunc
= gl_trans_elt_1ui_tab
[TYPE_IDX(type
)];
257 ctx
->Array
.NewArrayState
|= VERT_INDEX
;
258 ctx
->NewState
|= NEW_CLIENT_STATE
;
264 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
266 GET_CURRENT_CONTEXT(ctx
);
269 texUnit
= ctx
->Array
.ActiveTexture
;
271 if (size
<1 || size
>4) {
272 gl_error( ctx
, GL_INVALID_VALUE
, "glTexCoordPointer(size)" );
276 gl_error( ctx
, GL_INVALID_VALUE
, "glTexCoordPointer(stride)" );
280 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
281 fprintf(stderr
, "glTexCoordPointer( unit %u sz %d type %s stride %d )\n",
284 gl_lookup_enum_by_nr( type
),
287 ctx
->Array
.TexCoord
[texUnit
].StrideB
= stride
;
291 ctx
->Array
.TexCoord
[texUnit
].StrideB
= size
*sizeof(GLshort
);
294 ctx
->Array
.TexCoord
[texUnit
].StrideB
= size
*sizeof(GLint
);
297 ctx
->Array
.TexCoord
[texUnit
].StrideB
= size
*sizeof(GLfloat
);
300 ctx
->Array
.TexCoord
[texUnit
].StrideB
= size
*sizeof(GLdouble
);
303 gl_error( ctx
, GL_INVALID_ENUM
, "glTexCoordPointer(type)" );
307 ctx
->Array
.TexCoord
[texUnit
].Size
= size
;
308 ctx
->Array
.TexCoord
[texUnit
].Type
= type
;
309 ctx
->Array
.TexCoord
[texUnit
].Stride
= stride
;
310 ctx
->Array
.TexCoord
[texUnit
].Ptr
= (void *) ptr
;
312 ctx
->Array
.TexCoordFunc
[texUnit
] = gl_trans_4f_tab
[size
][TYPE_IDX(type
)];
313 ctx
->Array
.TexCoordEltFunc
[texUnit
] = gl_trans_elt_4f_tab
[size
][TYPE_IDX(type
)];
314 ctx
->Array
.NewArrayState
|= PIPE_TEX(texUnit
);
315 ctx
->NewState
|= NEW_CLIENT_STATE
;
322 _mesa_EdgeFlagPointer(GLsizei stride
, const void *vptr
)
324 GET_CURRENT_CONTEXT(ctx
);
325 const GLboolean
*ptr
= (GLboolean
*)vptr
;
328 gl_error( ctx
, GL_INVALID_VALUE
, "glEdgeFlagPointer(stride)" );
331 ctx
->Array
.EdgeFlag
.Stride
= stride
;
332 ctx
->Array
.EdgeFlag
.StrideB
= stride
? stride
: sizeof(GLboolean
);
333 ctx
->Array
.EdgeFlag
.Ptr
= (GLboolean
*) ptr
;
334 if (stride
!= sizeof(GLboolean
)) {
335 ctx
->Array
.EdgeFlagFunc
= gl_trans_1ub_tab
[TYPE_IDX(GL_UNSIGNED_BYTE
)];
337 ctx
->Array
.EdgeFlagFunc
= 0;
339 ctx
->Array
.EdgeFlagEltFunc
= gl_trans_elt_1ub_tab
[TYPE_IDX(GL_UNSIGNED_BYTE
)];
340 ctx
->Array
.NewArrayState
|= VERT_EDGE
;
341 ctx
->NewState
|= NEW_CLIENT_STATE
;
346 /* Called only from gl_DrawElements
348 static void gl_CVAEltPointer( GLcontext
*ctx
, GLenum type
, const GLvoid
*ptr
)
351 case GL_UNSIGNED_BYTE
:
352 ctx
->CVA
.Elt
.StrideB
= sizeof(GLubyte
);
354 case GL_UNSIGNED_SHORT
:
355 ctx
->CVA
.Elt
.StrideB
= sizeof(GLushort
);
357 case GL_UNSIGNED_INT
:
358 ctx
->CVA
.Elt
.StrideB
= sizeof(GLuint
);
361 gl_error( ctx
, GL_INVALID_ENUM
, "glEltPointer(type)" );
364 ctx
->CVA
.Elt
.Type
= type
;
365 ctx
->CVA
.Elt
.Stride
= 0;
366 ctx
->CVA
.Elt
.Ptr
= (void *) ptr
;
367 ctx
->CVA
.EltFunc
= gl_trans_1ui_tab
[TYPE_IDX(type
)];
368 ctx
->Array
.NewArrayState
|= VERT_ELT
; /* ??? */
375 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
376 GLsizei count
, const GLvoid
*ptr
)
379 _mesa_VertexPointer(size
, type
, stride
, ptr
);
384 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
388 _mesa_NormalPointer(type
, stride
, ptr
);
393 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
397 _mesa_ColorPointer(size
, type
, stride
, ptr
);
402 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
406 _mesa_IndexPointer(type
, stride
, ptr
);
411 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
412 GLsizei count
, const GLvoid
*ptr
)
415 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
420 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
423 _mesa_EdgeFlagPointer(stride
, ptr
);
430 /* KW: Batch function to exec all the array elements in the input
431 * buffer prior to transform. Done only the first time a vertex
432 * buffer is executed or compiled.
434 * KW: Have to do this after each glEnd if cva isn't active. (also
435 * have to do it after each full buffer)
437 void gl_exec_array_elements( GLcontext
*ctx
, struct immediate
*IM
,
441 GLuint
*flags
= IM
->Flag
;
442 GLuint
*elts
= IM
->Elt
;
443 GLuint translate
= ctx
->Array
.Flags
;
446 if (MESA_VERBOSE
&VERBOSE_IMMEDIATE
)
447 fprintf(stderr
, "exec_array_elements %d .. %d\n", start
, count
);
449 if (translate
& VERT_OBJ_ANY
)
450 (ctx
->Array
.VertexEltFunc
)( IM
->Obj
,
452 flags
, elts
, (VERT_ELT
|VERT_OBJ_ANY
),
455 if (translate
& VERT_NORM
)
456 (ctx
->Array
.NormalEltFunc
)( IM
->Normal
,
458 flags
, elts
, (VERT_ELT
|VERT_NORM
),
461 if (translate
& VERT_EDGE
)
462 (ctx
->Array
.EdgeFlagEltFunc
)( IM
->EdgeFlag
,
463 &ctx
->Array
.EdgeFlag
,
464 flags
, elts
, (VERT_ELT
|VERT_EDGE
),
467 if (translate
& VERT_RGBA
)
468 (ctx
->Array
.ColorEltFunc
)( IM
->Color
,
470 flags
, elts
, (VERT_ELT
|VERT_RGBA
),
473 if (translate
& VERT_INDEX
)
474 (ctx
->Array
.IndexEltFunc
)( IM
->Index
,
476 flags
, elts
, (VERT_ELT
|VERT_INDEX
),
479 if (translate
& VERT_TEX0_ANY
)
480 (ctx
->Array
.TexCoordEltFunc
[0])( IM
->TexCoord
[0],
481 &ctx
->Array
.TexCoord
[0],
482 flags
, elts
, (VERT_ELT
|VERT_TEX0_ANY
),
485 if (translate
& VERT_TEX1_ANY
)
486 (ctx
->Array
.TexCoordEltFunc
[1])( IM
->TexCoord
[1],
487 &ctx
->Array
.TexCoord
[1],
488 flags
, elts
, (VERT_ELT
|VERT_TEX1_ANY
),
492 for (i
= start
; i
< count
; i
++)
493 if (flags
[i
] & VERT_ELT
)
494 flags
[i
] |= translate
;
500 /* Enough funny business going on in here it might be quicker to use a
503 #define ARRAY_ELT( IM, i ) \
505 GLuint count = IM->Count; \
506 IM->Elt[count] = i; \
507 IM->Flag[count] = ((IM->Flag[count] & IM->ArrayAndFlags) | \
509 IM->FlushElt |= IM->ArrayEltFlush; \
510 IM->Count = count += IM->ArrayIncr; \
511 if (count == VB_MAX) \
512 IM->maybe_transform_vb( IM ); \
517 _mesa_ArrayElement( GLint i
)
525 gl_ArrayElement( GLcontext
*CC
, GLint i
)
527 struct immediate
*im
= CC
->input
;
534 _mesa_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
536 GET_CURRENT_CONTEXT(ctx
);
537 struct vertex_buffer
*VB
= ctx
->VB
;
540 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glDrawArrays");
543 gl_error( ctx
, GL_INVALID_VALUE
, "glDrawArrays(count)" );
547 if (!ctx
->CompileFlag
&& ctx
->Array
.Vertex
.Enabled
)
549 GLint remaining
= count
;
551 struct gl_client_array
*Normal
;
552 struct gl_client_array
*Color
;
553 struct gl_client_array
*Index
;
554 struct gl_client_array
*TexCoord
[MAX_TEXTURE_UNITS
];
555 struct gl_client_array
*EdgeFlag
;
556 struct immediate
*IM
= VB
->IM
;
557 struct gl_pipeline
*elt
= &ctx
->CVA
.elt
;
559 GLuint fallback
, required
;
562 gl_update_state( ctx
);
564 /* Just turn off cva on this path. Could be useful for multipass
565 * rendering to keep it turned on.
567 relock
= ctx
->CompileCVAFlag
;
570 ctx
->CompileCVAFlag
= 0;
571 elt
->pipeline_valid
= 0;
574 if (!elt
->pipeline_valid
)
575 gl_build_immediate_pipeline( ctx
);
577 required
= elt
->inputs
;
578 fallback
= (elt
->inputs
& ~ctx
->Array
.Summary
);
580 /* The translate function doesn't do anything about size. It
581 * just ensures that type and stride come out right.
583 IM
->v
.Obj
.size
= ctx
->Array
.Vertex
.Size
;
585 if (required
& VERT_RGBA
)
587 Color
= &ctx
->Array
.Color
;
588 if (fallback
& VERT_RGBA
) {
589 Color
= &ctx
->Fallback
.Color
;
590 ctx
->Array
.ColorFunc
=
591 gl_trans_4ub_tab
[4][TYPE_IDX(GL_UNSIGNED_BYTE
)];
595 if (required
& VERT_INDEX
)
597 Index
= &ctx
->Array
.Index
;
598 if (fallback
& VERT_INDEX
) {
599 Index
= &ctx
->Fallback
.Index
;
600 ctx
->Array
.IndexFunc
= gl_trans_1ui_tab
[TYPE_IDX(GL_UNSIGNED_INT
)];
604 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++)
606 GLuint flag
= VERT_TEX_ANY(i
);
608 if (required
& flag
) {
609 TexCoord
[i
] = &ctx
->Array
.TexCoord
[i
];
613 TexCoord
[i
] = &ctx
->Fallback
.TexCoord
[i
];
614 TexCoord
[i
]->Size
= gl_texcoord_size( ctx
->Current
.Flag
, i
);
616 ctx
->Array
.TexCoordFunc
[i
] =
617 gl_trans_4f_tab
[TexCoord
[i
]->Size
][TYPE_IDX(GL_FLOAT
)];
622 if (ctx
->Array
.Flags
!= ctx
->Array
.Flag
[0])
623 for (i
= 0 ; i
< VB_MAX
; i
++)
624 ctx
->Array
.Flag
[i
] = ctx
->Array
.Flags
;
627 if (required
& VERT_NORM
)
629 Normal
= &ctx
->Array
.Normal
;
630 if (fallback
& VERT_NORM
) {
631 Normal
= &ctx
->Fallback
.Normal
;
632 ctx
->Array
.NormalFunc
= gl_trans_3f_tab
[TYPE_IDX(GL_FLOAT
)];
636 if ( required
& VERT_EDGE
)
638 if (mode
== GL_TRIANGLES
||
642 EdgeFlag
= &ctx
->Array
.EdgeFlag
;
643 if (fallback
& VERT_EDGE
) {
644 EdgeFlag
= &ctx
->Fallback
.EdgeFlag
;
645 ctx
->Array
.EdgeFlagFunc
=
646 gl_trans_1ub_tab
[TYPE_IDX(GL_UNSIGNED_BYTE
)];
650 required
&= ~VERT_EDGE
;
653 VB
->Primitive
= IM
->Primitive
;
654 VB
->NextPrimitive
= IM
->NextPrimitive
;
655 VB
->MaterialMask
= IM
->MaterialMask
;
656 VB
->Material
= IM
->Material
;
659 while (remaining
> 0) {
660 GLint vbspace
= VB_MAX
- VB_START
;
663 if (vbspace
>= remaining
) {
665 VB
->LastPrimitive
= VB_START
+ n
;
668 VB
->LastPrimitive
= VB_START
;
673 ctx
->Array
.VertexFunc( IM
->Obj
+ VB_START
,
674 &ctx
->Array
.Vertex
, start
, n
);
676 if (required
& VERT_NORM
) {
677 ctx
->Array
.NormalFunc( IM
->Normal
+ VB_START
,
681 if (required
& VERT_EDGE
) {
682 ctx
->Array
.EdgeFlagFunc( IM
->EdgeFlag
+ VB_START
,
683 EdgeFlag
, start
, n
);
686 if (required
& VERT_RGBA
) {
687 ctx
->Array
.ColorFunc( IM
->Color
+ VB_START
,
691 if (required
& VERT_INDEX
) {
692 ctx
->Array
.IndexFunc( IM
->Index
+ VB_START
,
696 if (required
& VERT_TEX0_ANY
) {
697 IM
->v
.TexCoord
[0].size
= TexCoord
[0]->Size
;
698 ctx
->Array
.TexCoordFunc
[0]( IM
->TexCoord
[0] + VB_START
,
699 TexCoord
[0], start
, n
);
702 if (required
& VERT_TEX1_ANY
) {
703 IM
->v
.TexCoord
[1].size
= TexCoord
[1]->Size
;
704 ctx
->Array
.TexCoordFunc
[1]( IM
->TexCoord
[1] + VB_START
,
705 TexCoord
[1], start
, n
);
708 VB
->ObjPtr
= &IM
->v
.Obj
;
709 VB
->NormalPtr
= &IM
->v
.Normal
;
710 VB
->ColorPtr
= &IM
->v
.Color
;
711 VB
->Color
[0] = VB
->Color
[1] = VB
->ColorPtr
;
712 VB
->IndexPtr
= &IM
->v
.Index
;
713 VB
->EdgeFlagPtr
= &IM
->v
.EdgeFlag
;
714 VB
->TexCoordPtr
[0] = &IM
->v
.TexCoord
[0];
715 VB
->TexCoordPtr
[1] = &IM
->v
.TexCoord
[1];
717 VB
->Flag
= ctx
->Array
.Flag
;
718 VB
->OrFlag
= ctx
->Array
.Flags
;
720 VB
->Start
= IM
->Start
= VB_START
;
721 count
= VB
->Count
= IM
->Count
= VB_START
+ n
;
723 #define RESET_VEC(v, t, s, c) (v.start = t v.data[s], v.count = c)
725 RESET_VEC(IM
->v
.Obj
, (GLfloat
*), VB_START
, count
);
726 RESET_VEC(IM
->v
.Normal
, (GLfloat
*), VB_START
, count
);
727 RESET_VEC(IM
->v
.TexCoord
[0], (GLfloat
*), VB_START
, count
);
728 RESET_VEC(IM
->v
.TexCoord
[1], (GLfloat
*), VB_START
, count
);
729 RESET_VEC(IM
->v
.Index
, &, VB_START
, count
);
730 RESET_VEC(IM
->v
.Elt
, &, VB_START
, count
);
731 RESET_VEC(IM
->v
.EdgeFlag
, &, VB_START
, count
);
732 RESET_VEC(IM
->v
.Color
, (GLubyte
*), VB_START
, count
);
733 RESET_VEC(VB
->Clip
, (GLfloat
*), VB_START
, count
);
734 RESET_VEC(VB
->Eye
, (GLfloat
*), VB_START
, count
);
735 RESET_VEC(VB
->Win
, (GLfloat
*), VB_START
, count
);
736 RESET_VEC(VB
->BColor
, (GLubyte
*), VB_START
, count
);
737 RESET_VEC(VB
->BIndex
, &, VB_START
, count
);
739 VB
->NextPrimitive
[VB
->CopyStart
] = VB
->Count
;
740 VB
->Primitive
[VB
->CopyStart
] = mode
;
741 ctx
->Array
.Flag
[count
] |= VERT_END_VB
;
743 /* Transform and render.
745 gl_run_pipeline( VB
);
748 ctx
->Array
.Flag
[count
] = ctx
->Array
.Flags
;
749 ctx
->Array
.Flag
[VB_START
] = ctx
->Array
.Flags
;
755 gl_reset_input( ctx
);
758 ctx
->CompileCVAFlag
= relock
;
759 elt
->pipeline_valid
= 0;
762 else if (ctx
->Array
.Vertex
.Enabled
)
764 /* The GL_COMPILE and GL_COMPILE_AND_EXECUTE cases. These
765 * could be handled by the above code, but it gets a little
766 * complex. The generated list is still of good quality
769 gl_Begin( ctx
, mode
);
770 for (i
=0;i
<count
;i
++) {
771 gl_ArrayElement( ctx
, start
+i
);
777 /* The degenerate case where vertices are not enabled - only
778 * need to process the very final array element, as all of the
779 * preceding ones would be overwritten anyway.
781 gl_Begin( ctx
, mode
);
782 gl_ArrayElement( ctx
, start
+count
);
789 /* KW: Exactly fakes the effects of calling glArrayElement multiple times.
790 * Compilation is handled via. the IM->maybe_transform_vb() callback.
793 #define DRAW_ELT(FUNC, TYPE) \
794 static void FUNC( GLcontext *ctx, GLenum mode, \
795 TYPE *indices, GLuint count ) \
799 gl_Begin( ctx, mode ); \
801 for (j = 0 ; j < count ; ) { \
802 struct immediate *IM = ctx->input; \
803 GLuint start = IM->Start; \
804 GLuint nr = MIN2( VB_MAX, count - j + start ); \
805 GLuint sf = IM->Flag[start]; \
806 IM->FlushElt |= IM->ArrayEltFlush; \
808 for (i = start ; i < nr ; i++) { \
809 IM->Elt[i] = (GLuint) *indices++; \
810 IM->Flag[i] = VERT_ELT; \
813 if (j == 0) IM->Flag[start] |= sf; \
818 if (j == count) gl_End( ctx ); \
819 IM->maybe_transform_vb( IM ); \
823 #define DRAW_ELT(FUNC, TYPE) \
824 static void FUNC( GLcontext *ctx, GLenum mode, \
825 TYPE *indices, GLuint count ) \
829 for (i = 0 ; i < count ; i++) \
830 glArrayElement( indices[i] ); \
836 DRAW_ELT( draw_elt_ubyte
, GLubyte
)
837 DRAW_ELT( draw_elt_ushort
, GLushort
)
838 DRAW_ELT( draw_elt_uint
, GLuint
)
841 static GLuint natural_stride
[0x10] =
843 sizeof(GLbyte
), /* 0 */
844 sizeof(GLubyte
), /* 1 */
845 sizeof(GLshort
), /* 2 */
846 sizeof(GLushort
), /* 3 */
847 sizeof(GLint
), /* 4 */
848 sizeof(GLuint
), /* 5 */
849 sizeof(GLfloat
), /* 6 */
850 2 * sizeof(GLbyte
), /* 7 */
851 3 * sizeof(GLbyte
), /* 8 */
852 4 * sizeof(GLbyte
), /* 9 */
853 sizeof(GLdouble
), /* a */
863 _mesa_DrawElements(GLenum mode
, GLsizei count
, GLenum type
, const GLvoid
*indices
)
865 GET_CURRENT_CONTEXT(ctx
);
869 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glDrawElements");
873 gl_error( ctx
, GL_INVALID_VALUE
, "glDrawElements(count)" );
877 if (mode
< 0 || mode
> GL_POLYGON
) {
878 gl_error( ctx
, GL_INVALID_ENUM
, "glDrawArrays(mode)" );
882 if (type
!= GL_UNSIGNED_INT
&& type
!= GL_UNSIGNED_BYTE
&& type
!= GL_UNSIGNED_SHORT
)
884 gl_error( ctx
, GL_INVALID_ENUM
, "glDrawElements(type)" );
889 gl_update_state(ctx
);
891 if (ctx
->CompileCVAFlag
)
893 #if defined(MESA_CVA_PROF)
897 /* Treat VERT_ELT like a special client array.
899 ctx
->Array
.NewArrayState
|= VERT_ELT
;
900 ctx
->Array
.Summary
|= VERT_ELT
;
901 ctx
->Array
.Flags
|= VERT_ELT
;
903 cva
->elt_mode
= mode
;
904 cva
->elt_count
= count
;
905 cva
->Elt
.Type
= type
;
906 cva
->Elt
.Ptr
= (void *) indices
;
907 cva
->Elt
.StrideB
= natural_stride
[TYPE_IDX(type
)];
908 cva
->EltFunc
= gl_trans_1ui_tab
[TYPE_IDX(type
)];
910 if (!cva
->pre
.pipeline_valid
)
911 gl_build_precalc_pipeline( ctx
);
912 else if (MESA_VERBOSE
& VERBOSE_PIPELINE
)
913 fprintf(stderr
, ": dont rebuild\n");
915 gl_cva_force_precalc( ctx
);
917 /* Did we 'precalculate' the render op?
919 if (ctx
->CVA
.pre
.ops
& PIPE_OP_RENDER
) {
920 ctx
->Array
.NewArrayState
|= VERT_ELT
;
921 ctx
->Array
.Summary
&= ~VERT_ELT
;
922 ctx
->Array
.Flags
&= ~VERT_ELT
;
926 if ( (MESA_VERBOSE
&VERBOSE_VARRAY
) )
927 printf("using immediate\n");
931 /* Otherwise, have to use the immediate path to render.
934 case GL_UNSIGNED_BYTE
:
936 GLubyte
*ub_indices
= (GLubyte
*) indices
;
937 if (ctx
->Array
.Summary
& VERT_OBJ_ANY
) {
938 draw_elt_ubyte( ctx
, mode
, ub_indices
, count
);
940 gl_ArrayElement( ctx
, (GLuint
) ub_indices
[count
-1] );
944 case GL_UNSIGNED_SHORT
:
946 GLushort
*us_indices
= (GLushort
*) indices
;
947 if (ctx
->Array
.Summary
& VERT_OBJ_ANY
) {
948 draw_elt_ushort( ctx
, mode
, us_indices
, count
);
950 gl_ArrayElement( ctx
, (GLuint
) us_indices
[count
-1] );
954 case GL_UNSIGNED_INT
:
956 GLuint
*ui_indices
= (GLuint
*) indices
;
957 if (ctx
->Array
.Summary
& VERT_OBJ_ANY
) {
958 draw_elt_uint( ctx
, mode
, ui_indices
, count
);
960 gl_ArrayElement( ctx
, ui_indices
[count
-1] );
965 gl_error( ctx
, GL_INVALID_ENUM
, "glDrawElements(type)" );
969 if (ctx
->CompileCVAFlag
) {
970 ctx
->Array
.NewArrayState
|= VERT_ELT
;
971 ctx
->Array
.Summary
&= ~VERT_ELT
;
978 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
980 GET_CURRENT_CONTEXT(ctx
);
981 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
982 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
984 GLenum ctype
; /* color type */
985 GLint coffset
, noffset
, voffset
;/* color, normal, vertex offsets */
986 GLint defstride
; /* default stride */
991 c
= f
* ((4*sizeof(GLubyte
) + (f
-1)) / f
);
994 gl_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1000 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1001 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1006 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1007 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1012 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1013 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1014 ctype
= GL_UNSIGNED_BYTE
;
1017 defstride
= c
+ 2*f
;
1020 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1021 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1022 ctype
= GL_UNSIGNED_BYTE
;
1025 defstride
= c
+ 3*f
;
1028 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1029 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1036 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1037 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1042 case GL_C4F_N3F_V3F
:
1043 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1044 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1052 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1053 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1058 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1059 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1063 case GL_T2F_C4UB_V3F
:
1064 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1065 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1066 ctype
= GL_UNSIGNED_BYTE
;
1071 case GL_T2F_C3F_V3F
:
1072 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1073 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1079 case GL_T2F_N3F_V3F
:
1080 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1081 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1086 case GL_T2F_C4F_N3F_V3F
:
1087 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1088 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1095 case GL_T4F_C4F_N3F_V4F
:
1096 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1097 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1105 gl_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1113 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1114 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1117 coordUnitSave
= ctx
->Array
.ActiveTexture
;
1120 GLint factor
= ctx
->Array
.TexCoordInterleaveFactor
;
1121 for (i
= 0; i
< factor
; i
++) {
1122 _mesa_ClientActiveTextureARB( (GLenum
) (GL_TEXTURE0_ARB
+ i
) );
1123 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1124 glTexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1125 (GLubyte
*) pointer
+ i
* coffset
);
1127 for (i
= factor
; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
1128 _mesa_ClientActiveTextureARB( (GLenum
) (GL_TEXTURE0_ARB
+ i
) );
1129 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1134 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
1135 _mesa_ClientActiveTextureARB( (GLenum
) (GL_TEXTURE0_ARB
+ i
) );
1136 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1139 /* Restore texture coordinate unit index */
1140 _mesa_ClientActiveTextureARB( (GLenum
) (GL_TEXTURE0_ARB
+ coordUnitSave
) );
1145 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1146 glColorPointer( ccomps
, ctype
, stride
,
1147 (GLubyte
*) pointer
+ coffset
);
1150 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1156 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1157 glNormalPointer( GL_FLOAT
, stride
,
1158 (GLubyte
*) pointer
+ noffset
);
1161 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1164 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1165 glVertexPointer( vcomps
, GL_FLOAT
, stride
,
1166 (GLubyte
*) pointer
+ voffset
);
1172 _mesa_DrawRangeElements(GLenum mode
, GLuint start
,
1173 GLuint end
, GLsizei count
,
1174 GLenum type
, const GLvoid
*indices
)
1176 GET_CURRENT_CONTEXT(ctx
);
1179 gl_error(ctx
, GL_INVALID_VALUE
, "glDrawRangeElements( end < start )");
1185 * XXX something in locked arrays is broken! If start = 0,
1186 * end = 1 and count = 2 we'll take the LockArrays path and
1187 * get incorrect results. See Scott McMillan's bug of 3 Jan 2000.
1188 * For now, don't use locked arrays.
1190 if (!ctx
->Array
.LockCount
&& 2*count
> (GLint
) 3*(end
-start
)) {
1191 glLockArraysEXT( start
, end
);
1192 glDrawElements( mode
, count
, type
, indices
);
1193 glUnlockArraysEXT();
1195 glDrawElements( mode
, count
, type
, indices
);
1198 glDrawElements( mode
, count
, type
, indices
);
1204 void gl_update_client_state( GLcontext
*ctx
)
1206 static GLuint sz_flags
[5] = { 0,
1212 static GLuint tc_flags
[5] = { 0,
1218 ctx
->Array
.Flags
= 0;
1219 ctx
->Array
.Summary
= 0;
1220 ctx
->input
->ArrayIncr
= 0;
1222 if (ctx
->Array
.Normal
.Enabled
) ctx
->Array
.Flags
|= VERT_NORM
;
1223 if (ctx
->Array
.Color
.Enabled
) ctx
->Array
.Flags
|= VERT_RGBA
;
1224 if (ctx
->Array
.Index
.Enabled
) ctx
->Array
.Flags
|= VERT_INDEX
;
1225 if (ctx
->Array
.EdgeFlag
.Enabled
) ctx
->Array
.Flags
|= VERT_EDGE
;
1226 if (ctx
->Array
.Vertex
.Enabled
) {
1227 ctx
->Array
.Flags
|= sz_flags
[ctx
->Array
.Vertex
.Size
];
1228 ctx
->input
->ArrayIncr
= 1;
1230 if (ctx
->Array
.TexCoord
[0].Enabled
) {
1231 ctx
->Array
.Flags
|= tc_flags
[ctx
->Array
.TexCoord
[0].Size
];
1233 if (ctx
->Array
.TexCoord
[1].Enabled
) {
1234 ctx
->Array
.Flags
|= (tc_flags
[ctx
->Array
.TexCoord
[1].Size
] << NR_TEXSIZE_BITS
);
1237 /* Not really important any more:
1239 ctx
->Array
.Summary
= ctx
->Array
.Flags
& VERT_DATA
;
1240 ctx
->input
->ArrayAndFlags
= ~ctx
->Array
.Flags
;
1241 ctx
->input
->ArrayEltFlush
= !(ctx
->CompileCVAFlag
);