1 /* $Id: varray.c,v 1.4 1999/10/08 09:27:11 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 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.
35 #include "GL/xf86glx.h"
48 #include "translate.h"
54 #include "vbindirect.h"
58 #include "GL/xf86glx.h"
62 #if defined(GLX_DIRECT_RENDERING) && !defined(XFree86Server) && !defined(GLX_USE_DLOPEN)
63 #define NEED_MESA_FUNCS_WRAPPED
68 void GLAPIENTRY
glVertexPointer(CTX_ARG GLint size
, GLenum type
, GLsizei stride
,
76 if (size
<2 || size
>4) {
77 gl_error( ctx
, GL_INVALID_VALUE
, "glVertexPointer(size)" );
81 gl_error( ctx
, GL_INVALID_VALUE
, "glVertexPointer(stride)" );
85 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
86 fprintf(stderr
, "glVertexPointer( sz %d type %s stride %d )\n", size
,
87 gl_lookup_enum_by_nr( type
),
90 ctx
->Array
.Vertex
.StrideB
= stride
;
94 ctx
->Array
.Vertex
.StrideB
= size
*sizeof(GLshort
);
97 ctx
->Array
.Vertex
.StrideB
= size
*sizeof(GLint
);
100 ctx
->Array
.Vertex
.StrideB
= size
*sizeof(GLfloat
);
103 ctx
->Array
.Vertex
.StrideB
= size
*sizeof(GLdouble
);
106 gl_error( ctx
, GL_INVALID_ENUM
, "glVertexPointer(type)" );
110 ctx
->Array
.Vertex
.Size
= size
;
111 ctx
->Array
.Vertex
.Type
= type
;
112 ctx
->Array
.Vertex
.Stride
= stride
;
113 ctx
->Array
.Vertex
.Ptr
= (void *) ptr
;
114 ctx
->Array
.VertexFunc
= gl_trans_4f_tab
[size
][TYPE_IDX(type
)];
115 ctx
->Array
.VertexEltFunc
= gl_trans_elt_4f_tab
[size
][TYPE_IDX(type
)];
116 ctx
->Array
.NewArrayState
|= VERT_OBJ_ANY
;
117 ctx
->NewState
|= NEW_CLIENT_STATE
;
123 void GLAPIENTRY
glNormalPointer(CTX_ARG GLenum type
, GLsizei stride
,
132 gl_error( ctx
, GL_INVALID_VALUE
, "glNormalPointer(stride)" );
136 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
137 fprintf(stderr
, "glNormalPointer( type %s stride %d )\n",
138 gl_lookup_enum_by_nr( type
),
141 ctx
->Array
.Normal
.StrideB
= stride
;
145 ctx
->Array
.Normal
.StrideB
= 3*sizeof(GLbyte
);
148 ctx
->Array
.Normal
.StrideB
= 3*sizeof(GLshort
);
151 ctx
->Array
.Normal
.StrideB
= 3*sizeof(GLint
);
154 ctx
->Array
.Normal
.StrideB
= 3*sizeof(GLfloat
);
157 ctx
->Array
.Normal
.StrideB
= 3*sizeof(GLdouble
);
160 gl_error( ctx
, GL_INVALID_ENUM
, "glNormalPointer(type)" );
164 ctx
->Array
.Normal
.Type
= type
;
165 ctx
->Array
.Normal
.Stride
= stride
;
166 ctx
->Array
.Normal
.Ptr
= (void *) ptr
;
167 ctx
->Array
.NormalFunc
= gl_trans_3f_tab
[TYPE_IDX(type
)];
168 ctx
->Array
.NormalEltFunc
= gl_trans_elt_3f_tab
[TYPE_IDX(type
)];
169 ctx
->Array
.NewArrayState
|= VERT_NORM
;
170 ctx
->NewState
|= NEW_CLIENT_STATE
;
175 void GLAPIENTRY
glColorPointer(CTX_ARG GLint size
, GLenum type
, GLsizei stride
,
182 if (size
<3 || size
>4) {
183 gl_error( ctx
, GL_INVALID_VALUE
, "glColorPointer(size)" );
187 gl_error( ctx
, GL_INVALID_VALUE
, "glColorPointer(stride)" );
191 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
192 fprintf(stderr
, "glColorPointer( sz %d type %s stride %d )\n", size
,
193 gl_lookup_enum_by_nr( type
),
196 ctx
->Array
.Color
.StrideB
= stride
;
200 ctx
->Array
.Color
.StrideB
= size
*sizeof(GLbyte
);
202 case GL_UNSIGNED_BYTE
:
203 ctx
->Array
.Color
.StrideB
= size
*sizeof(GLubyte
);
206 ctx
->Array
.Color
.StrideB
= size
*sizeof(GLshort
);
208 case GL_UNSIGNED_SHORT
:
209 ctx
->Array
.Color
.StrideB
= size
*sizeof(GLushort
);
212 ctx
->Array
.Color
.StrideB
= size
*sizeof(GLint
);
214 case GL_UNSIGNED_INT
:
215 ctx
->Array
.Color
.StrideB
= size
*sizeof(GLuint
);
218 ctx
->Array
.Color
.StrideB
= size
*sizeof(GLfloat
);
221 ctx
->Array
.Color
.StrideB
= size
*sizeof(GLdouble
);
224 gl_error( ctx
, GL_INVALID_ENUM
, "glColorPointer(type)" );
228 ctx
->Array
.Color
.Size
= size
;
229 ctx
->Array
.Color
.Type
= type
;
230 ctx
->Array
.Color
.Stride
= stride
;
231 ctx
->Array
.Color
.Ptr
= (void *) ptr
;
232 ctx
->Array
.ColorFunc
= gl_trans_4ub_tab
[size
][TYPE_IDX(type
)];
233 ctx
->Array
.ColorEltFunc
= gl_trans_elt_4ub_tab
[size
][TYPE_IDX(type
)];
234 ctx
->Array
.NewArrayState
|= VERT_RGBA
;
235 ctx
->NewState
|= NEW_CLIENT_STATE
;
240 void GLAPIENTRY
glIndexPointer(CTX_ARG GLenum type
, GLsizei stride
,
249 gl_error( ctx
, GL_INVALID_VALUE
, "glIndexPointer(stride)" );
253 ctx
->Array
.Index
.StrideB
= stride
;
256 case GL_UNSIGNED_BYTE
:
257 ctx
->Array
.Index
.StrideB
= sizeof(GLubyte
);
260 ctx
->Array
.Index
.StrideB
= sizeof(GLshort
);
263 ctx
->Array
.Index
.StrideB
= sizeof(GLint
);
266 ctx
->Array
.Index
.StrideB
= sizeof(GLfloat
);
269 ctx
->Array
.Index
.StrideB
= sizeof(GLdouble
);
272 gl_error( ctx
, GL_INVALID_ENUM
, "glIndexPointer(type)" );
276 ctx
->Array
.Index
.Type
= type
;
277 ctx
->Array
.Index
.Stride
= stride
;
278 ctx
->Array
.Index
.Ptr
= (void *) ptr
;
279 ctx
->Array
.IndexFunc
= gl_trans_1ui_tab
[TYPE_IDX(type
)];
280 ctx
->Array
.IndexEltFunc
= gl_trans_elt_1ui_tab
[TYPE_IDX(type
)];
281 ctx
->Array
.NewArrayState
|= VERT_INDEX
;
282 ctx
->NewState
|= NEW_CLIENT_STATE
;
287 void GLAPIENTRY
glTexCoordPointer(CTX_ARG GLint size
, GLenum type
,
288 GLsizei stride
, const GLvoid
*ptr
)
297 texUnit
= ctx
->Array
.ActiveTexture
;
299 if (size
<1 || size
>4) {
300 gl_error( ctx
, GL_INVALID_VALUE
, "glTexCoordPointer(size)" );
304 gl_error( ctx
, GL_INVALID_VALUE
, "glTexCoordPointer(stride)" );
308 if (MESA_VERBOSE
&(VERBOSE_VARRAY
|VERBOSE_API
))
309 fprintf(stderr
, "glTexCoordPointer( unit %u sz %d type %s stride %d )\n",
312 gl_lookup_enum_by_nr( type
),
315 ctx
->Array
.TexCoord
[texUnit
].StrideB
= stride
;
319 ctx
->Array
.TexCoord
[texUnit
].StrideB
= size
*sizeof(GLshort
);
322 ctx
->Array
.TexCoord
[texUnit
].StrideB
= size
*sizeof(GLint
);
325 ctx
->Array
.TexCoord
[texUnit
].StrideB
= size
*sizeof(GLfloat
);
328 ctx
->Array
.TexCoord
[texUnit
].StrideB
= size
*sizeof(GLdouble
);
331 gl_error( ctx
, GL_INVALID_ENUM
, "glTexCoordPointer(type)" );
335 ctx
->Array
.TexCoord
[texUnit
].Size
= size
;
336 ctx
->Array
.TexCoord
[texUnit
].Type
= type
;
337 ctx
->Array
.TexCoord
[texUnit
].Stride
= stride
;
338 ctx
->Array
.TexCoord
[texUnit
].Ptr
= (void *) ptr
;
340 ctx
->Array
.TexCoordFunc
[texUnit
] = gl_trans_4f_tab
[size
][TYPE_IDX(type
)];
341 ctx
->Array
.TexCoordEltFunc
[texUnit
] = gl_trans_elt_4f_tab
[size
][TYPE_IDX(type
)];
342 ctx
->Array
.NewArrayState
|= PIPE_TEX(texUnit
);
343 ctx
->NewState
|= NEW_CLIENT_STATE
;
349 void GLAPIENTRY
glEdgeFlagPointer(CTX_ARG GLsizei stride
, const void *vptr
)
351 const GLboolean
*ptr
= (GLboolean
*)vptr
;
359 gl_error( ctx
, GL_INVALID_VALUE
, "glEdgeFlagPointer(stride)" );
362 ctx
->Array
.EdgeFlag
.Stride
= stride
;
363 ctx
->Array
.EdgeFlag
.StrideB
= stride
? stride
: sizeof(GLboolean
);
364 ctx
->Array
.EdgeFlag
.Ptr
= (GLboolean
*) ptr
;
365 if (stride
!= sizeof(GLboolean
)) {
366 ctx
->Array
.EdgeFlagFunc
= gl_trans_1ub_tab
[TYPE_IDX(GL_UNSIGNED_BYTE
)];
368 ctx
->Array
.EdgeFlagFunc
= 0;
370 ctx
->Array
.EdgeFlagEltFunc
= gl_trans_elt_1ub_tab
[TYPE_IDX(GL_UNSIGNED_BYTE
)];
371 ctx
->Array
.NewArrayState
|= VERT_EDGE
;
372 ctx
->NewState
|= NEW_CLIENT_STATE
;
376 /* Called only from gl_DrawElements
378 void gl_CVAEltPointer( GLcontext
*ctx
, GLenum type
, const GLvoid
*ptr
)
381 case GL_UNSIGNED_BYTE
:
382 ctx
->CVA
.Elt
.StrideB
= sizeof(GLubyte
);
384 case GL_UNSIGNED_SHORT
:
385 ctx
->CVA
.Elt
.StrideB
= sizeof(GLushort
);
387 case GL_UNSIGNED_INT
:
388 ctx
->CVA
.Elt
.StrideB
= sizeof(GLuint
);
391 gl_error( ctx
, GL_INVALID_ENUM
, "glEltPointer(type)" );
394 ctx
->CVA
.Elt
.Type
= type
;
395 ctx
->CVA
.Elt
.Stride
= 0;
396 ctx
->CVA
.Elt
.Ptr
= (void *) ptr
;
397 ctx
->CVA
.EltFunc
= gl_trans_1ui_tab
[TYPE_IDX(type
)];
398 ctx
->Array
.NewArrayState
|= VERT_ELT
; /* ??? */
403 /* KW: Batch function to exec all the array elements in the input
404 * buffer prior to transform. Done only the first time a vertex
405 * buffer is executed or compiled.
407 void gl_exec_array_elements( GLcontext
*ctx
, struct immediate
*IM
)
409 GLuint
*flags
= IM
->Flag
;
410 GLuint
*elts
= IM
->Elt
;
411 GLuint count
= IM
->Count
;
412 GLuint start
= IM
->Start
;
413 GLuint translate
= ctx
->Array
.Flags
;
416 if (translate
& VERT_OBJ_ANY
)
417 (ctx
->Array
.VertexEltFunc
)( IM
->Obj
,
419 flags
, elts
, (VERT_ELT
|VERT_OBJ_ANY
),
422 if (translate
& VERT_NORM
)
423 (ctx
->Array
.NormalEltFunc
)( IM
->Normal
,
425 flags
, elts
, (VERT_ELT
|VERT_NORM
),
428 if (translate
& VERT_EDGE
)
429 (ctx
->Array
.EdgeFlagEltFunc
)( IM
->EdgeFlag
,
430 &ctx
->Array
.EdgeFlag
,
431 flags
, elts
, (VERT_ELT
|VERT_EDGE
),
434 if (translate
& VERT_RGBA
)
435 (ctx
->Array
.ColorEltFunc
)( IM
->Color
,
437 flags
, elts
, (VERT_ELT
|VERT_RGBA
),
440 if (translate
& VERT_INDEX
)
441 (ctx
->Array
.IndexEltFunc
)( IM
->Index
,
443 flags
, elts
, (VERT_ELT
|VERT_INDEX
),
446 if (translate
& VERT_TEX0_ANY
)
447 (ctx
->Array
.TexCoordEltFunc
[0])( IM
->TexCoord
[0],
448 &ctx
->Array
.TexCoord
[0],
449 flags
, elts
, (VERT_ELT
|VERT_TEX0_ANY
),
452 if (translate
& VERT_TEX1_ANY
)
453 (ctx
->Array
.TexCoordEltFunc
[1])( IM
->TexCoord
[1],
454 &ctx
->Array
.TexCoord
[1],
455 flags
, elts
, (VERT_ELT
|VERT_TEX1_ANY
),
458 IM
->OrFlag
|= translate
;
460 /* Lighting ignores the and-flag, so still need to do this.
462 if (IM
->AndFlag
& VERT_ELT
) {
463 for (i
= 0 ; i
< count
; i
++)
464 flags
[i
] |= translate
;
465 IM
->AndFlag
|= translate
;
468 for (i
= 0 ; i
< count
; i
++) {
469 if (flags
[i
] & VERT_ELT
) flags
[i
] |= translate
;
472 IM
->AndFlag
= andflag
;
478 /* KW: I think this is moving in the right direction, but it still feels
479 * like we are doing way too much work.
481 void gl_DrawArrays( GLcontext
*ctx
, GLenum mode
, GLint start
, GLsizei count
)
483 struct vertex_buffer
*VB
= ctx
->VB
;
486 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glDrawArrays");
489 gl_error( ctx
, GL_INVALID_VALUE
, "glDrawArrays(count)" );
493 if (!ctx
->CompileFlag
&& ctx
->Array
.Vertex
.Enabled
)
495 GLint remaining
= count
;
499 GLvector4f tc
[MAX_TEXTURE_UNITS
];
503 GLuint update
= 0, translate
= 0;
504 struct vertex_array_pointers VSrc
;
505 struct immediate
*IM
= VB
->IM
;
506 struct gl_client_array
*client_data
;
507 struct gl_pipeline
*elt
= &ctx
->CVA
.elt
;
509 GLuint fallback
, required
;
512 gl_update_state( ctx
);
514 /* This will die miserably with CVA... Need more work to support this.
516 relock
= ctx
->CompileCVAFlag
;
517 ctx
->CompileCVAFlag
= 0;
519 if (!elt
->pipeline_valid
|| relock
)
520 gl_build_immediate_pipeline( ctx
);
522 required
= elt
->inputs
;
523 fallback
= (elt
->inputs
& ~ctx
->Array
.Summary
);
525 VSrc
.Color
= &IM
->v
.Color
;
526 VSrc
.Index
= &IM
->v
.Index
;
527 VSrc
.EdgeFlag
= &IM
->v
.EdgeFlag
;
528 VSrc
.TexCoord
[0] = &IM
->v
.TexCoord
[0];
529 VSrc
.TexCoord
[1] = &IM
->v
.TexCoord
[1];
530 VSrc
.Obj
= &IM
->v
.Obj
;
531 VSrc
.Normal
= &IM
->v
.Normal
;
533 if (required
& VERT_RGBA
)
535 client_data
= &ctx
->Array
.Color
;
536 if (fallback
& VERT_RGBA
)
537 client_data
= &ctx
->Fallback
.Color
;
539 if (client_data
->Type
== GL_UNSIGNED_BYTE
&&
540 client_data
->Size
== 4)
543 col
.data
= (GLubyte (*)[4]) client_data
->Ptr
;
544 col
.stride
= client_data
->StrideB
;
545 col
.flags
= VEC_NOT_WRITABLE
|VEC_GOOD_STRIDE
;
546 if (client_data
->StrideB
!= 4 * sizeof(GLubyte
))
547 col
.flags
^= VEC_STRIDE_FLAGS
;
551 translate
|= VERT_RGBA
;
555 if (required
& VERT_INDEX
)
557 client_data
= &ctx
->Array
.Index
;
558 if (fallback
& VERT_INDEX
)
559 client_data
= &ctx
->Fallback
.Index
;
561 if (client_data
->Type
== GL_UNSIGNED_INT
)
564 index
.data
= (GLuint
*) client_data
->Ptr
;
565 index
.stride
= client_data
->StrideB
;
566 index
.flags
= VEC_NOT_WRITABLE
|VEC_GOOD_STRIDE
;
567 if (client_data
->StrideB
!= sizeof(GLuint
))
568 index
.flags
^= VEC_STRIDE_FLAGS
;
570 update
|= VERT_INDEX
;
572 translate
|= VERT_INDEX
;
576 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++)
578 GLuint flag
= VERT_TEX_ANY(i
);
580 if (required
& flag
) {
582 client_data
= &ctx
->Array
.TexCoord
[i
];
586 client_data
= &ctx
->Fallback
.TexCoord
[i
];
587 client_data
->Size
= gl_texcoord_size( ctx
->Current
.Flag
, i
);
590 if (client_data
->Type
== GL_FLOAT
)
592 VSrc
.TexCoord
[i
] = &tc
[i
];
593 tc
[i
].data
= (GLfloat (*)[4]) client_data
->Ptr
;
594 tc
[i
].stride
= client_data
->StrideB
;
595 tc
[i
].size
= client_data
->Size
;
596 tc
[i
].flags
= VEC_NOT_WRITABLE
|VEC_GOOD_STRIDE
;
597 if (tc
[i
].stride
|= 4 * sizeof(GLfloat
))
598 tc
[i
].flags
^= VEC_STRIDE_FLAGS
;
606 if (ctx
->Array
.Flags
!= ctx
->Array
.Flag
[0])
607 for (i
= 0 ; i
< VB_MAX
; i
++)
608 ctx
->Array
.Flag
[i
] = ctx
->Array
.Flags
;
611 if (ctx
->Array
.Vertex
.Type
== GL_FLOAT
)
614 obj
.data
= (GLfloat (*)[4]) ctx
->Array
.Vertex
.Ptr
;
615 obj
.stride
= ctx
->Array
.Vertex
.StrideB
;
616 obj
.size
= ctx
->Array
.Vertex
.Size
;
617 obj
.flags
= VEC_NOT_WRITABLE
|VEC_GOOD_STRIDE
;
618 if (obj
.stride
!= 4 * sizeof(GLfloat
))
619 obj
.flags
^= VEC_STRIDE_FLAGS
;
621 update
|= VERT_OBJ_ANY
;
625 translate
|= VERT_OBJ_ANY
;
628 if (required
& VERT_NORM
)
630 client_data
= &ctx
->Array
.Normal
;
631 if (fallback
& VERT_NORM
)
632 client_data
= &ctx
->Fallback
.Normal
;
634 if (client_data
->Type
== GL_FLOAT
)
638 norm
.data
= (GLfloat (*)[3]) client_data
->Ptr
;
639 norm
.stride
= client_data
->StrideB
;
642 translate
|= VERT_NORM
;
646 if ( (required
& VERT_EDGE
) &&
647 (mode
== GL_TRIANGLES
||
651 client_data
= &ctx
->Array
.EdgeFlag
;
653 if (fallback
& VERT_EDGE
)
654 client_data
= &ctx
->Fallback
.EdgeFlag
;
656 VSrc
.EdgeFlag
= &edge
;
657 edge
.data
= (GLboolean
*) client_data
->Ptr
;
658 edge
.stride
= client_data
->StrideB
;
659 edge
.flags
= VEC_NOT_WRITABLE
|VEC_GOOD_STRIDE
;
660 if (edge
.stride
!= sizeof(GLubyte
))
661 edge
.flags
^= VEC_STRIDE_FLAGS
;
666 VB
->Primitive
= IM
->Primitive
;
667 VB
->NextPrimitive
= IM
->NextPrimitive
;
668 VB
->MaterialMask
= IM
->MaterialMask
;
669 VB
->Material
= IM
->Material
;
672 while (remaining
> 0) {
673 GLint vbspace
= VB_MAX
- VB_START
;
677 if (vbspace
>= remaining
) {
679 VB
->LastPrimitive
= VB_START
+ n
;
682 VB
->LastPrimitive
= VB_START
;
691 if (update
& VERT_OBJ_ANY
)
692 obj
.start
= VEC_ELT(&obj
, GLfloat
, start
);
694 if (update
& VERT_NORM
)
695 norm
.start
= VEC_ELT(&norm
, GLfloat
, start
);
697 if (update
& VERT_EDGE
)
698 edge
.start
= VEC_ELT(&edge
, GLubyte
, start
);
700 if (update
& VERT_RGBA
)
701 col
.start
= VEC_ELT(&col
, GLubyte
, start
);
703 if (update
& VERT_INDEX
)
704 index
.start
= VEC_ELT(&index
, GLuint
, start
);
706 if (update
& VERT_TEX0_ANY
)
707 tc
[0].start
= VEC_ELT(&tc
[0], GLfloat
, start
);
709 if (update
& VERT_TEX1_ANY
)
710 tc
[1].start
= VEC_ELT(&tc
[1], GLfloat
, start
);
714 /* Translate data to fix up type and stride.
717 if (translate
& VERT_OBJ_ANY
) {
718 ctx
->Array
.VertexFunc( IM
->Obj
+ VB_START
,
719 &ctx
->Array
.Vertex
, start
, n
);
722 if (translate
& VERT_NORM
) {
723 ctx
->Array
.NormalFunc( IM
->Normal
+ VB_START
,
724 &ctx
->Array
.Normal
, start
, n
);
727 if (translate
& VERT_EDGE
) {
728 ctx
->Array
.EdgeFlagFunc( IM
->EdgeFlag
+ VB_START
,
729 &ctx
->Array
.EdgeFlag
, start
, n
);
732 if (translate
& VERT_RGBA
) {
733 ctx
->Array
.ColorFunc( IM
->Color
+ VB_START
,
734 &ctx
->Array
.Color
, start
, n
);
737 if (translate
& VERT_INDEX
) {
738 ctx
->Array
.IndexFunc( IM
->Index
+ VB_START
,
739 &ctx
->Array
.Index
, start
, n
);
742 if (translate
& VERT_TEX0_ANY
) {
743 IM
->v
.TexCoord
[0].size
= tc
[0].size
;
744 ctx
->Array
.TexCoordFunc
[0]( IM
->TexCoord
[0] + VB_START
,
745 &ctx
->Array
.TexCoord
[0], start
, n
);
748 if (translate
& VERT_TEX1_ANY
) {
749 IM
->v
.TexCoord
[1].size
= tc
[1].size
;
750 ctx
->Array
.TexCoordFunc
[1]( IM
->TexCoord
[1] + VB_START
,
751 &ctx
->Array
.TexCoord
[1], start
, n
);
756 VB
->ObjPtr
= VSrc
.Obj
;
757 VB
->NormalPtr
= VSrc
.Normal
;
758 VB
->Color
[0] = VB
->Color
[1] = VB
->ColorPtr
= VSrc
.Color
;
759 VB
->IndexPtr
= VSrc
.Index
;
760 VB
->EdgeFlagPtr
= VSrc
.EdgeFlag
;
761 VB
->TexCoordPtr
[0] = VSrc
.TexCoord
[0];
762 VB
->TexCoordPtr
[1] = VSrc
.TexCoord
[1];
764 VB
->Flag
= ctx
->Array
.Flag
;
765 VB
->AndFlag
= ctx
->Array
.Flags
;
766 VB
->OrFlag
= ctx
->Array
.Flags
;
768 count
= VB
->Count
= VB_START
+ n
;
770 VB
->ObjPtr
->count
= count
;
771 VB
->NormalPtr
->count
= count
;
772 VB
->ColorPtr
->count
= count
;
773 VB
->IndexPtr
->count
= count
;
774 VB
->EdgeFlagPtr
->count
= count
;
775 VB
->TexCoordPtr
[0]->count
= count
;
776 VB
->TexCoordPtr
[1]->count
= count
;
778 VB
->Flag
[count
] |= VERT_END_VB
;
779 VB
->Flag
[VB_START
] |= VERT_NORM
;
780 /* VB->Flag[VB_START] |= (IM->Flag[vb_start] & VERT_MATERIAL); */
782 VB
->NextPrimitive
[VB
->CopyStart
] = VB
->Count
;
783 VB
->Primitive
[VB
->CopyStart
] = mode
;
785 /* Transform and render.
787 gl_run_pipeline( VB
);
790 ctx
->Array
.Flag
[count
] = ctx
->Array
.Flags
;
791 ctx
->Array
.Flag
[VB_START
] = ctx
->Array
.Flags
;
792 IM
->Flag
[VB_START
] = 0;
798 ctx
->CompileCVAFlag
= relock
;
800 else if (ctx
->Array
.Vertex
.Enabled
)
802 /* The GL_COMPILE and GL_COMPILE_AND_EXECUTE cases. These
803 * could be handled by the above code, but it gets a little
806 /* No need to reset - never called from inside a display list */
807 gl_Begin( ctx
, mode
);
808 for (i
=0;i
<count
;i
++) {
809 gl_ArrayElement( ctx
, start
+i
);
815 /* The degenerate case where vertices are not enabled - only
816 * need to process the very final array element, as all of the
817 * preceding ones would be overwritten anyway.
819 gl_Begin( ctx
, mode
);
820 gl_ArrayElement( ctx
, start
+count
);
827 /* KW: Exactly fakes the effects of calling glArrayElement multiple times.
828 * Compilation is handled via. the IM->maybe_transform_vb() callback.
830 #define DRAW_ELT(FUNC, TYPE) \
831 static void FUNC( GLcontext *ctx, GLenum mode, \
832 TYPE *indices, GLuint count ) \
836 if (count) gl_Begin( ctx, mode ); \
838 for (j = 0 ; j < count ; ) { \
839 GLuint nr = MIN2( VB_MAX, count - j + VB_START ); \
840 struct immediate *IM = ctx->input; \
841 GLuint sf = IM->Flag[VB_START]; \
843 for (i = VB_START ; i < nr ; i++) { \
844 IM->Elt[i] = (GLuint) *indices++; \
845 IM->Flag[i] = VERT_ELT; \
848 if (j == 0) IM->Flag[VB_START] |= sf; \
851 j += nr - VB_START; \
853 if (j == count) gl_End( ctx ); \
855 IM->maybe_transform_vb( IM ); \
859 DRAW_ELT( draw_elt_ubyte
, GLubyte
)
860 DRAW_ELT( draw_elt_ushort
, GLushort
)
861 DRAW_ELT( draw_elt_uint
, GLuint
)
864 static GLuint natural_stride
[0x10] =
866 sizeof(GLbyte
), /* 0 */
867 sizeof(GLubyte
), /* 1 */
868 sizeof(GLshort
), /* 2 */
869 sizeof(GLushort
), /* 3 */
870 sizeof(GLint
), /* 4 */
871 sizeof(GLuint
), /* 5 */
872 sizeof(GLfloat
), /* 6 */
873 2 * sizeof(GLbyte
), /* 7 */
874 3 * sizeof(GLbyte
), /* 8 */
875 4 * sizeof(GLbyte
), /* 9 */
876 sizeof(GLdouble
), /* a */
884 void GLAPIENTRY
glDrawElements(CTX_ARG GLenum mode
, GLsizei count
,
885 GLenum type
, const GLvoid
*indices
)
895 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glDrawElements");
898 gl_error( ctx
, GL_INVALID_VALUE
, "glDrawElements(count)" );
902 if (mode
< 0 || mode
> GL_POLYGON
) {
903 gl_error( ctx
, GL_INVALID_ENUM
, "glDrawArrays(mode)" );
907 if (type
!= GL_UNSIGNED_INT
&& type
!= GL_UNSIGNED_BYTE
&& type
!= GL_UNSIGNED_SHORT
)
909 gl_error( ctx
, GL_INVALID_ENUM
, "glDrawElements(type)" );
914 gl_update_state(ctx
);
916 if (ctx
->CompileCVAFlag
)
918 #if defined(MESA_CVA_PROF)
922 /* Treat VERT_ELT like a special client array.
924 ctx
->Array
.NewArrayState
|= VERT_ELT
;
925 ctx
->Array
.Summary
|= VERT_ELT
;
926 ctx
->Array
.Flags
|= VERT_ELT
;
928 cva
->elt_mode
= mode
;
929 cva
->elt_count
= count
;
930 cva
->Elt
.Type
= type
;
931 cva
->Elt
.Ptr
= (void *) indices
;
932 cva
->Elt
.StrideB
= natural_stride
[TYPE_IDX(type
)];
933 cva
->EltFunc
= gl_trans_1ui_tab
[TYPE_IDX(type
)];
935 if (!cva
->pre
.pipeline_valid
)
936 gl_build_precalc_pipeline( ctx
);
937 else if (MESA_VERBOSE
& VERBOSE_PIPELINE
)
938 fprintf(stderr
, ": dont rebuild\n");
940 gl_cva_force_precalc( ctx
);
942 /* Did we 'precalculate' the render op?
944 if (ctx
->CVA
.pre
.ops
& PIPE_OP_RENDER
) {
945 ctx
->Array
.NewArrayState
|= VERT_ELT
;
946 ctx
->Array
.Summary
&= ~VERT_ELT
;
947 ctx
->Array
.Flags
&= ~VERT_ELT
;
951 if ( (MESA_VERBOSE
&VERBOSE_VARRAY
) )
952 printf("using immediate\n");
956 /* Otherwise, have to use the immediate path to render.
959 case GL_UNSIGNED_BYTE
:
961 GLubyte
*ub_indices
= (GLubyte
*) indices
;
962 if (ctx
->Array
.Summary
& VERT_OBJ_ANY
) {
963 draw_elt_ubyte( ctx
, mode
, ub_indices
, count
);
965 gl_ArrayElement( ctx
, (GLuint
) ub_indices
[count
-1] );
969 case GL_UNSIGNED_SHORT
:
971 GLushort
*us_indices
= (GLushort
*) indices
;
972 if (ctx
->Array
.Summary
& VERT_OBJ_ANY
) {
973 draw_elt_ushort( ctx
, mode
, us_indices
, count
);
975 gl_ArrayElement( ctx
, (GLuint
) us_indices
[count
-1] );
979 case GL_UNSIGNED_INT
:
981 GLuint
*ui_indices
= (GLuint
*) indices
;
982 if (ctx
->Array
.Summary
& VERT_OBJ_ANY
) {
983 draw_elt_uint( ctx
, mode
, ui_indices
, count
);
985 gl_ArrayElement( ctx
, ui_indices
[count
-1] );
990 gl_error( ctx
, GL_INVALID_ENUM
, "glDrawElements(type)" );
994 if (ctx
->CompileCVAFlag
) {
995 ctx
->Array
.NewArrayState
|= VERT_ELT
;
996 ctx
->Array
.Summary
&= ~VERT_ELT
;
1002 void GLAPIENTRY
glInterleavedArrays(CTX_ARG GLenum format
, GLsizei stride
,
1003 const GLvoid
*pointer
)
1006 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1007 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1009 GLenum ctype
; /* color type */
1010 GLint coffset
, noffset
, voffset
;/* color, normal, vertex offsets */
1011 GLint defstride
; /* default stride */
1013 GLint coordUnitSave
;
1020 f
= sizeof(GLfloat
);
1021 c
= f
* ((4*sizeof(GLubyte
) + (f
-1)) / f
);
1024 gl_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1030 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1031 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1036 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1037 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1042 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1043 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1044 ctype
= GL_UNSIGNED_BYTE
;
1047 defstride
= c
+ 2*f
;
1050 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1051 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1052 ctype
= GL_UNSIGNED_BYTE
;
1055 defstride
= c
+ 3*f
;
1058 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1059 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1066 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1067 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1072 case GL_C4F_N3F_V3F
:
1073 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1074 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1082 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1083 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1088 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1089 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1093 case GL_T2F_C4UB_V3F
:
1094 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1095 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1096 ctype
= GL_UNSIGNED_BYTE
;
1101 case GL_T2F_C3F_V3F
:
1102 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1103 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1109 case GL_T2F_N3F_V3F
:
1110 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1111 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1116 case GL_T2F_C4F_N3F_V3F
:
1117 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1118 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1125 case GL_T4F_C4F_N3F_V4F
:
1126 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1127 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1135 gl_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1143 gl_DisableClientState( ctx
, GL_EDGE_FLAG_ARRAY
);
1144 gl_DisableClientState( ctx
, GL_INDEX_ARRAY
);
1147 coordUnitSave
= ctx
->Array
.ActiveTexture
;
1150 GLint factor
= ctx
->Array
.TexCoordInterleaveFactor
;
1151 for (i
= 0; i
< factor
; i
++) {
1152 gl_ActiveTexture( ctx
, (GLenum
) (GL_TEXTURE0_ARB
+ i
) );
1153 gl_EnableClientState( ctx
, GL_TEXTURE_COORD_ARRAY
);
1154 glTexCoordPointer(CTX_PRM tcomps
, GL_FLOAT
, stride
,
1155 (GLubyte
*) pointer
+ i
* coffset
);
1157 for (i
= factor
; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
1158 gl_ActiveTexture( ctx
, (GLenum
) (GL_TEXTURE0_ARB
+ i
) );
1159 gl_DisableClientState( ctx
, GL_TEXTURE_COORD_ARRAY
);
1164 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
1165 gl_ActiveTexture( ctx
, (GLenum
) (GL_TEXTURE0_ARB
+ i
) );
1166 gl_DisableClientState( ctx
, GL_TEXTURE_COORD_ARRAY
);
1169 /* Restore texture coordinate unit index */
1170 gl_ActiveTexture( ctx
, (GLenum
) (GL_TEXTURE0_ARB
+ coordUnitSave
) );
1175 gl_EnableClientState( ctx
, GL_COLOR_ARRAY
);
1176 glColorPointer(CTX_PRM ccomps
, ctype
, stride
,
1177 (GLubyte
*) pointer
+ coffset
);
1180 gl_DisableClientState( ctx
, GL_COLOR_ARRAY
);
1186 gl_EnableClientState( ctx
, GL_NORMAL_ARRAY
);
1187 glNormalPointer(CTX_PRM GL_FLOAT
, stride
,
1188 (GLubyte
*) pointer
+ noffset
);
1191 gl_DisableClientState( ctx
, GL_NORMAL_ARRAY
);
1194 gl_EnableClientState( ctx
, GL_VERTEX_ARRAY
);
1195 glVertexPointer(CTX_PRM vcomps
, GL_FLOAT
, stride
,
1196 (GLubyte
*) pointer
+ voffset
);
1201 void GLAPIENTRY
glDrawRangeElements(CTX_ARG GLenum mode
, GLuint start
,
1202 GLuint end
, GLsizei count
,
1203 GLenum type
, const GLvoid
*indices
)
1211 gl_error(ctx
, GL_INVALID_VALUE
, "glDrawRangeElements( end < start )");
1215 if (!ctx
->Array
.LockCount
&& 2*count
> 3*(end
-start
)) {
1216 glLockArraysEXT(CTX_PRM start
, end
);
1217 glDrawElements(CTX_PRM mode
, count
, type
, indices
);
1218 glUnlockArraysEXT(CTX_VPRM
);
1220 glDrawElements(CTX_PRM mode
, count
, type
, indices
);
1226 void gl_update_client_state( GLcontext
*ctx
)
1228 static GLuint sz_flags
[5] = { 0,
1234 static GLuint tc_flags
[5] = { 0,
1240 ctx
->Array
.Flags
= 0;
1241 ctx
->Array
.Summary
= 0;
1242 ctx
->input
->ArrayIncr
= 0;
1244 if (ctx
->Array
.Normal
.Enabled
) ctx
->Array
.Flags
|= VERT_NORM
;
1245 if (ctx
->Array
.Color
.Enabled
) ctx
->Array
.Flags
|= VERT_RGBA
;
1246 if (ctx
->Array
.Index
.Enabled
) ctx
->Array
.Flags
|= VERT_INDEX
;
1247 if (ctx
->Array
.EdgeFlag
.Enabled
) ctx
->Array
.Flags
|= VERT_EDGE
;
1248 if (ctx
->Array
.Vertex
.Enabled
) {
1249 ctx
->Array
.Flags
|= sz_flags
[ctx
->Array
.Vertex
.Size
];
1250 ctx
->input
->ArrayIncr
= 1;
1252 if (ctx
->Array
.TexCoord
[0].Enabled
) {
1253 ctx
->Array
.Flags
|= tc_flags
[ctx
->Array
.TexCoord
[0].Size
];
1255 if (ctx
->Array
.TexCoord
[1].Enabled
) {
1256 ctx
->Array
.Flags
|= (tc_flags
[ctx
->Array
.TexCoord
[1].Size
] << NR_TEXSIZE_BITS
);
1259 /* Not really important any more:
1261 ctx
->Array
.Summary
= ctx
->Array
.Flags
& VERT_DATA
;
1262 ctx
->input
->ArrayAndFlags
= ~ctx
->Array
.Flags
;
1263 ctx
->input
->ArrayEltFlush
= !(ctx
->CompileCVAFlag
);