2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Keith Whitwell <keith@tungstengraphics.com>
31 * Template for render stages which build and emit vertices directly
32 * to fixed-size dma buffers. Useful for rendering strips and other
33 * native primitives where clipping and per-vertex tweaks such as
34 * those in t_dd_tritmp.h are not required.
36 * Produces code for both inline triangles and indexed triangles.
37 * Where various primitive types are unaccelerated by hardware, the
38 * code attempts to fallback to other primitive types (quadstrips to
39 * tristrips, lineloops to linestrips), or to indexed vertices.
42 #if !defined(HAVE_TRIANGLES)
43 #error "must have at least triangles to use render template"
47 #define ELTS_VARS(buf)
48 #define ALLOC_ELTS(nr) 0
49 #define EMIT_ELT( offset, elt )
50 #define EMIT_TWO_ELTS( offset, elt0, elt1 )
51 #define INCR_ELTS( nr )
52 #define ELT_INIT(prim)
53 #define GET_CURRENT_VB_MAX_ELTS() 0
54 #define GET_SUBSEQUENT_VB_MAX_ELTS() 0
55 #define RELEASE_ELT_VERTS()
56 #define EMIT_INDEXED_VERTS( ctx, start, count )
60 #define EMIT_TWO_ELTS( offset, elt0, elt1 ) \
62 EMIT_ELT( offset, elt0 ); \
63 EMIT_ELT( offset+1, elt1 ); \
68 /**********************************************************************/
69 /* Render whole begin/end objects */
70 /**********************************************************************/
76 static void *TAG(emit_elts
)( GLcontext
*ctx
, GLuint
*elts
, GLuint nr
,
83 for ( i
= 0 ; i
+1 < nr
; i
+=2, elts
+= 2 ) {
84 EMIT_TWO_ELTS( 0, elts
[0], elts
[1] );
89 EMIT_ELT( 0, elts
[0] );
93 return (void *)ELTPTR
;
97 static __inline
void *TAG(emit_verts
)( GLcontext
*ctx
, GLuint start
,
98 GLuint count
, void *buf
)
100 return EMIT_VERTS(ctx
, start
, count
, buf
);
103 /***********************************************************************
104 * Render non-indexed primitives.
105 ***********************************************************************/
107 static void TAG(render_points_verts
)( GLcontext
*ctx
,
114 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
120 currentsz
= GET_CURRENT_VB_MAX_VERTS();
124 for (j
= start
; j
< count
; j
+= nr
) {
125 nr
= MIN2( currentsz
, count
- j
);
126 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
131 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
136 static void TAG(render_lines_verts
)( GLcontext
*ctx
,
143 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
149 /* Emit whole number of lines in total and in each buffer:
151 count
-= (count
-start
) & 1;
152 currentsz
= GET_CURRENT_VB_MAX_VERTS();
153 currentsz
-= currentsz
& 1;
159 for (j
= start
; j
< count
; j
+= nr
) {
160 nr
= MIN2( currentsz
, count
- j
);
161 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
166 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
172 static void TAG(render_line_strip_verts
)( GLcontext
*ctx
,
177 if (HAVE_LINE_STRIPS
) {
179 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
183 INIT( GL_LINE_STRIP
);
185 currentsz
= GET_CURRENT_VB_MAX_VERTS();
189 for (j
= start
; j
+ 1 < count
; j
+= nr
- 1 ) {
190 nr
= MIN2( currentsz
, count
- j
);
191 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
198 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
204 static void TAG(render_line_loop_verts
)( GLcontext
*ctx
,
209 if (HAVE_LINE_STRIPS
) {
211 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
215 INIT( GL_LINE_STRIP
);
217 if (flags
& PRIM_BEGIN
)
222 /* Ensure last vertex won't wrap buffers:
224 currentsz
= GET_CURRENT_VB_MAX_VERTS();
233 for ( ; j
+ 1 < count
; j
+= nr
- 1 ) {
234 nr
= MIN2( currentsz
, count
- j
);
236 if (j
+ nr
>= count
&&
241 tmp
= ALLOC_VERTS(nr
+1);
242 tmp
= TAG(emit_verts
)( ctx
, j
, nr
, tmp
);
243 tmp
= TAG(emit_verts
)( ctx
, start
, 1, tmp
);
247 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
253 else if (start
+ 1 < count
&& (flags
& PRIM_END
)) {
255 tmp
= ALLOC_VERTS(2);
256 tmp
= TAG(emit_verts
)( ctx
, start
+1, 1, tmp
);
257 tmp
= TAG(emit_verts
)( ctx
, start
, 1, tmp
);
263 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
269 static void TAG(render_triangles_verts
)( GLcontext
*ctx
,
275 int dmasz
= (GET_SUBSEQUENT_VB_MAX_VERTS()/3) * 3;
281 currentsz
= (GET_CURRENT_VB_MAX_VERTS()/3) * 3;
283 /* Emit whole number of tris in total. dmasz is already a multiple
286 count
-= (count
-start
)%3;
291 for (j
= start
; j
< count
; j
+= nr
) {
292 nr
= MIN2( currentsz
, count
- j
);
293 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
300 static void TAG(render_tri_strip_verts
)( GLcontext
*ctx
,
305 if (HAVE_TRI_STRIPS
) {
308 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
311 INIT(GL_TRIANGLE_STRIP
);
313 currentsz
= GET_CURRENT_VB_MAX_VERTS();
319 /* From here on emit even numbers of tris when wrapping over buffers:
321 dmasz
-= (dmasz
& 1);
322 currentsz
-= (currentsz
& 1);
324 for (j
= start
; j
+ 2 < count
; j
+= nr
- 2 ) {
325 nr
= MIN2( currentsz
, count
- j
);
326 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
333 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
338 static void TAG(render_tri_fan_verts
)( GLcontext
*ctx
,
346 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
349 INIT(GL_TRIANGLE_FAN
);
351 currentsz
= GET_CURRENT_VB_MAX_VERTS();
356 for (j
= start
+ 1 ; j
+ 1 < count
; j
+= nr
- 2 ) {
358 nr
= MIN2( currentsz
, count
- j
+ 1 );
359 tmp
= ALLOC_VERTS( nr
);
360 tmp
= TAG(emit_verts
)( ctx
, start
, 1, tmp
);
361 tmp
= TAG(emit_verts
)( ctx
, j
, nr
- 1, tmp
);
368 /* Could write code to emit these as indexed vertices (for the
369 * g400, for instance).
371 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
377 static void TAG(render_poly_verts
)( GLcontext
*ctx
,
385 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
390 currentsz
= GET_CURRENT_VB_MAX_VERTS();
395 for (j
= start
+ 1 ; j
+ 1 < count
; j
+= nr
- 2 ) {
397 nr
= MIN2( currentsz
, count
- j
+ 1 );
398 tmp
= ALLOC_VERTS( nr
);
399 tmp
= TAG(emit_verts
)( ctx
, start
, 1, tmp
);
400 tmp
= TAG(emit_verts
)( ctx
, j
, nr
- 1, tmp
);
406 else if (HAVE_TRI_FANS
&& ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
407 TAG(render_tri_fan_verts
)( ctx
, start
, count
, flags
);
409 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
414 static void TAG(render_quad_strip_verts
)( GLcontext
*ctx
,
421 if (HAVE_QUAD_STRIPS
) {
424 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
429 currentsz
= GET_CURRENT_VB_MAX_VERTS();
434 dmasz
-= (dmasz
& 2);
435 currentsz
-= (currentsz
& 2);
437 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
438 nr
= MIN2( currentsz
, count
- j
);
439 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
445 } else if (HAVE_TRI_STRIPS
&&
446 ctx
->Light
.ShadeModel
== GL_FLAT
&&
447 TNL_CONTEXT(ctx
)->vb
.ColorPtr
[0]->stride
) {
450 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
454 EMIT_INDEXED_VERTS( ctx
, start
, count
);
456 /* Simulate flat-shaded quadstrips using indexed vertices:
458 ELT_INIT( GL_TRIANGLES
);
460 currentsz
= GET_CURRENT_VB_MAX_ELTS();
462 /* Emit whole number of quads in total, and in each buffer.
465 count
-= (count
-start
) & 1;
466 currentsz
-= currentsz
& 1;
471 currentsz
= currentsz
/6*2;
474 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
475 nr
= MIN2( currentsz
, count
- j
);
477 GLint quads
= (nr
/2)-1;
479 ELTS_VARS( ALLOC_ELTS( quads
*6 ) );
481 for ( i
= j
-start
; i
< j
-start
+quads
*2 ; i
+=2 ) {
482 EMIT_TWO_ELTS( 0, (i
+0), (i
+1) );
483 EMIT_TWO_ELTS( 2, (i
+2), (i
+1) );
484 EMIT_TWO_ELTS( 4, (i
+3), (i
+2) );
497 /* Vertices won't fit in a single buffer or elts not
498 * available - should never happen.
500 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
504 else if (HAVE_TRI_STRIPS
) {
506 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
509 /* Emit smooth-shaded quadstrips as tristrips:
512 INIT( GL_TRIANGLE_STRIP
);
514 /* Emit whole number of quads in total, and in each buffer.
517 currentsz
= GET_CURRENT_VB_MAX_VERTS();
518 currentsz
-= currentsz
& 1;
519 count
-= (count
-start
) & 1;
525 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
526 nr
= MIN2( currentsz
, count
- j
);
527 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
534 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
540 static void TAG(render_quads_verts
)( GLcontext
*ctx
,
547 int dmasz
= (GET_SUBSEQUENT_VB_MAX_VERTS()/4) * 4;
553 /* Emit whole number of quads in total. dmasz is already a multiple
556 count
-= (count
-start
)%4;
558 currentsz
= (GET_CURRENT_VB_MAX_VERTS()/4) * 4;
562 for (j
= start
; j
< count
; j
+= nr
) {
563 nr
= MIN2( currentsz
, count
- j
);
564 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
568 else if (HAVE_ELTS
) {
569 /* Hardware doesn't have a quad primitive type -- try to
570 * simulate it using indexed vertices and the triangle
574 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
578 EMIT_INDEXED_VERTS( ctx
, start
, count
);
581 ELT_INIT( GL_TRIANGLES
);
582 currentsz
= GET_CURRENT_VB_MAX_ELTS();
584 /* Emit whole number of quads in total, and in each buffer.
587 count
-= (count
-start
) & 3;
588 currentsz
-= currentsz
& 3;
590 /* Adjust for rendering as triangles:
592 currentsz
= currentsz
/6*4;
598 for (j
= start
; j
< count
; j
+= nr
) {
599 nr
= MIN2( currentsz
, count
- j
);
603 ELTS_VARS( ALLOC_ELTS( quads
*6 ) );
605 for ( i
= j
-start
; i
< j
-start
+quads
*4 ; i
+=4 ) {
606 EMIT_TWO_ELTS( 0, (i
+0), (i
+1) );
607 EMIT_TWO_ELTS( 2, (i
+3), (i
+1) );
608 EMIT_TWO_ELTS( 4, (i
+2), (i
+3) );
619 else if (HAVE_TRIANGLES
) {
620 /* Hardware doesn't have a quad primitive type -- try to
621 * simulate it using triangle primitive. This is a win for
622 * gears, but is it useful in the broader world?
629 for (j
= start
; j
< count
-3; j
+= 4) {
630 void *tmp
= ALLOC_VERTS( 6 );
633 tmp
= EMIT_VERTS(ctx
, j
, 2, tmp
);
634 tmp
= EMIT_VERTS(ctx
, j
+ 3, 1, tmp
);
637 tmp
= EMIT_VERTS(ctx
, j
+ 1, 3, tmp
);
641 /* Vertices won't fit in a single buffer, should never happen.
643 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
648 static void TAG(render_noop
)( GLcontext
*ctx
,
658 static tnl_render_func
TAG(render_tab_verts
)[GL_POLYGON
+2] =
660 TAG(render_points_verts
),
661 TAG(render_lines_verts
),
662 TAG(render_line_loop_verts
),
663 TAG(render_line_strip_verts
),
664 TAG(render_triangles_verts
),
665 TAG(render_tri_strip_verts
),
666 TAG(render_tri_fan_verts
),
667 TAG(render_quads_verts
),
668 TAG(render_quad_strip_verts
),
669 TAG(render_poly_verts
),
674 /****************************************************************************
675 * Render elts using hardware indexed verts *
676 ****************************************************************************/
679 static void TAG(render_points_elts
)( GLcontext
*ctx
,
686 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
688 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
691 ELT_INIT( GL_POINTS
);
693 currentsz
= GET_CURRENT_VB_MAX_ELTS();
697 for (j
= start
; j
< count
; j
+= nr
) {
698 nr
= MIN2( currentsz
, count
- j
);
699 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
704 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
711 static void TAG(render_lines_elts
)( GLcontext
*ctx
,
718 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
720 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
723 ELT_INIT( GL_LINES
);
725 /* Emit whole number of lines in total and in each buffer:
727 count
-= (count
-start
) & 1;
728 currentsz
-= currentsz
& 1;
731 currentsz
= GET_CURRENT_VB_MAX_ELTS();
735 for (j
= start
; j
< count
; j
+= nr
) {
736 nr
= MIN2( currentsz
, count
- j
);
737 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
742 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
748 static void TAG(render_line_strip_elts
)( GLcontext
*ctx
,
753 if (HAVE_LINE_STRIPS
) {
755 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
757 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
760 FLUSH(); /* always a new primitive */
761 ELT_INIT( GL_LINE_STRIP
);
763 currentsz
= GET_CURRENT_VB_MAX_ELTS();
767 for (j
= start
; j
+ 1 < count
; j
+= nr
- 1 ) {
768 nr
= MIN2( currentsz
, count
- j
);
769 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
774 /* TODO: Try to emit as indexed lines.
776 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
782 static void TAG(render_line_loop_elts
)( GLcontext
*ctx
,
787 if (HAVE_LINE_STRIPS
) {
789 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
791 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
795 ELT_INIT( GL_LINE_STRIP
);
797 if (flags
& PRIM_BEGIN
)
802 currentsz
= GET_CURRENT_VB_MAX_ELTS();
807 /* Ensure last vertex doesn't wrap:
813 for ( ; j
+ 1 < count
; j
+= nr
- 1 ) {
814 nr
= MIN2( currentsz
, count
- j
);
816 if (j
+ nr
>= count
&&
821 tmp
= ALLOC_ELTS(nr
+1);
822 tmp
= TAG(emit_elts
)( ctx
, elts
+j
, nr
, tmp
);
823 tmp
= TAG(emit_elts
)( ctx
, elts
+start
, 1, tmp
);
826 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
832 else if (start
+ 1 < count
&& (flags
& PRIM_END
)) {
835 tmp
= TAG(emit_elts
)( ctx
, elts
+start
+1, 1, tmp
);
836 tmp
= TAG(emit_elts
)( ctx
, elts
+start
, 1, tmp
);
841 /* TODO: Try to emit as indexed lines */
842 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
848 /* For verts, we still eliminate the copy from main memory to dma
849 * buffers. For elts, this is probably no better (worse?) than the
852 static void TAG(render_triangles_elts
)( GLcontext
*ctx
,
858 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
859 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS()/3*3;
864 ELT_INIT( GL_TRIANGLES
);
866 currentsz
= GET_CURRENT_VB_MAX_ELTS();
868 /* Emit whole number of tris in total. dmasz is already a multiple
871 count
-= (count
-start
)%3;
872 currentsz
-= currentsz
%3;
876 for (j
= start
; j
< count
; j
+= nr
) {
877 nr
= MIN2( currentsz
, count
- j
);
878 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
886 static void TAG(render_tri_strip_elts
)( GLcontext
*ctx
,
891 if (HAVE_TRI_STRIPS
) {
894 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
895 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
899 ELT_INIT( GL_TRIANGLE_STRIP
);
901 currentsz
= GET_CURRENT_VB_MAX_ELTS();
906 /* Keep the same winding over multiple buffers:
908 dmasz
-= (dmasz
& 1);
909 currentsz
-= (currentsz
& 1);
911 for (j
= start
; j
+ 2 < count
; j
+= nr
- 2 ) {
912 nr
= MIN2( currentsz
, count
- j
);
913 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
918 /* TODO: try to emit as indexed triangles */
919 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
924 static void TAG(render_tri_fan_elts
)( GLcontext
*ctx
,
931 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
933 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
937 ELT_INIT( GL_TRIANGLE_FAN
);
939 currentsz
= GET_CURRENT_VB_MAX_ELTS();
944 for (j
= start
+ 1 ; j
+ 1 < count
; j
+= nr
- 2 ) {
946 nr
= MIN2( currentsz
, count
- j
+ 1 );
947 tmp
= ALLOC_ELTS( nr
);
948 tmp
= TAG(emit_elts
)( ctx
, elts
+start
, 1, tmp
);
949 tmp
= TAG(emit_elts
)( ctx
, elts
+j
, nr
- 1, tmp
);
954 /* TODO: try to emit as indexed triangles */
955 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
961 static void TAG(render_poly_elts
)( GLcontext
*ctx
,
968 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
970 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
974 ELT_INIT( GL_POLYGON
);
976 currentsz
= GET_CURRENT_VB_MAX_ELTS();
981 for (j
= start
+ 1 ; j
+ 1 < count
; j
+= nr
- 2 ) {
983 nr
= MIN2( currentsz
, count
- j
+ 1 );
984 tmp
= ALLOC_ELTS( nr
);
985 tmp
= TAG(emit_elts
)( ctx
, elts
+start
, 1, tmp
);
986 tmp
= TAG(emit_elts
)( ctx
, elts
+j
, nr
- 1, tmp
);
990 } else if (HAVE_TRI_FANS
&& ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
991 TAG(render_tri_fan_verts
)( ctx
, start
, count
, flags
);
993 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
998 static void TAG(render_quad_strip_elts
)( GLcontext
*ctx
,
1003 if (HAVE_QUAD_STRIPS
&& 0) {
1005 else if (HAVE_TRI_STRIPS
) {
1007 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
1008 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
1013 currentsz
= GET_CURRENT_VB_MAX_ELTS();
1015 /* Emit whole number of quads in total, and in each buffer.
1018 count
-= (count
-start
) & 1;
1019 currentsz
-= currentsz
& 1;
1024 if (ctx
->Light
.ShadeModel
== GL_FLAT
) {
1025 ELT_INIT( GL_TRIANGLES
);
1027 currentsz
= currentsz
/6*2;
1030 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
1031 nr
= MIN2( currentsz
, count
- j
);
1036 GLint quads
= (nr
/2)-1;
1037 ELTS_VARS( ALLOC_ELTS( quads
*6 ) );
1039 for ( i
= j
-start
; i
< j
-start
+quads
; i
++, elts
+= 2 ) {
1040 EMIT_TWO_ELTS( 0, elts
[0], elts
[1] );
1041 EMIT_TWO_ELTS( 2, elts
[2], elts
[1] );
1042 EMIT_TWO_ELTS( 4, elts
[3], elts
[2] );
1053 ELT_INIT( GL_TRIANGLE_STRIP
);
1055 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
1056 nr
= MIN2( currentsz
, count
- j
);
1057 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
1066 static void TAG(render_quads_elts
)( GLcontext
*ctx
,
1073 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
1074 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS()/4*4;
1079 ELT_INIT( GL_TRIANGLES
);
1081 currentsz
= GET_CURRENT_VB_MAX_ELTS()/4*4;
1083 count
-= (count
-start
)%4;
1088 for (j
= start
; j
< count
; j
+= nr
) {
1089 nr
= MIN2( currentsz
, count
- j
);
1090 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
1096 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
1097 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
1101 ELT_INIT( GL_TRIANGLES
);
1102 currentsz
= GET_CURRENT_VB_MAX_ELTS();
1104 /* Emit whole number of quads in total, and in each buffer.
1107 count
-= (count
-start
) & 3;
1108 currentsz
-= currentsz
& 3;
1110 /* Adjust for rendering as triangles:
1112 currentsz
= currentsz
/6*4;
1118 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
1119 nr
= MIN2( currentsz
, count
- j
);
1125 ELTS_VARS( ALLOC_ELTS( quads
* 6 ) );
1127 for ( i
= j
-start
; i
< j
-start
+quads
; i
++, elts
+= 4 ) {
1128 EMIT_TWO_ELTS( 0, elts
[0], elts
[1] );
1129 EMIT_TWO_ELTS( 2, elts
[3], elts
[1] );
1130 EMIT_TWO_ELTS( 4, elts
[2], elts
[3] );
1144 static tnl_render_func
TAG(render_tab_elts
)[GL_POLYGON
+2] =
1146 TAG(render_points_elts
),
1147 TAG(render_lines_elts
),
1148 TAG(render_line_loop_elts
),
1149 TAG(render_line_strip_elts
),
1150 TAG(render_triangles_elts
),
1151 TAG(render_tri_strip_elts
),
1152 TAG(render_tri_fan_elts
),
1153 TAG(render_quads_elts
),
1154 TAG(render_quad_strip_elts
),
1155 TAG(render_poly_elts
),
1165 /* Pre-check the primitives in the VB to prevent the need for
1166 * fallbacks later on.
1168 static GLboolean
TAG(validate_render
)( GLcontext
*ctx
,
1169 struct vertex_buffer
*VB
)
1173 if (VB
->ClipOrMask
& ~CLIP_CULL_BIT
)
1176 if (VB
->Elts
&& !HAVE_ELTS
)
1179 for (i
= 0 ; i
< VB
->PrimitiveCount
; i
++) {
1180 GLuint prim
= VB
->Primitive
[i
].mode
;
1181 GLuint count
= VB
->Primitive
[i
].count
;
1182 GLboolean ok
= GL_FALSE
;
1187 switch (prim
& PRIM_MODE_MASK
) {
1192 ok
= HAVE_LINES
&& !ctx
->Line
.StippleFlag
;
1195 ok
= HAVE_LINE_STRIPS
&& !ctx
->Line
.StippleFlag
;
1198 ok
= HAVE_LINE_STRIPS
&& !ctx
->Line
.StippleFlag
;
1201 ok
= HAVE_TRIANGLES
;
1203 case GL_TRIANGLE_STRIP
:
1204 ok
= HAVE_TRI_STRIPS
;
1206 case GL_TRIANGLE_FAN
:
1210 if (HAVE_POLYGONS
) {
1214 ok
= (HAVE_TRI_FANS
&& ctx
->Light
.ShadeModel
== GL_SMOOTH
);
1219 ok
= HAVE_TRI_STRIPS
;
1221 else if (HAVE_QUAD_STRIPS
) {
1223 } else if (HAVE_TRI_STRIPS
&&
1224 ctx
->Light
.ShadeModel
== GL_FLAT
&&
1225 VB
->ColorPtr
[0]->stride
!= 0) {
1227 ok
= (GLint
) count
< GET_SUBSEQUENT_VB_MAX_ELTS();
1234 ok
= HAVE_TRI_STRIPS
;
1239 } else if (HAVE_ELTS
) {
1240 ok
= (GLint
) count
< GET_SUBSEQUENT_VB_MAX_ELTS();
1243 ok
= HAVE_TRIANGLES
; /* flatshading is ok. */
1251 /* fprintf(stderr, "not ok %s\n", _mesa_lookup_enum_by_nr(prim & PRIM_MODE_MASK)); */