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
);
264 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
270 static void TAG(render_triangles_verts
)( GLcontext
*ctx
,
276 int dmasz
= (GET_SUBSEQUENT_VB_MAX_VERTS()/3) * 3;
282 currentsz
= (GET_CURRENT_VB_MAX_VERTS()/3) * 3;
284 /* Emit whole number of tris in total. dmasz is already a multiple
287 count
-= (count
-start
)%3;
292 for (j
= start
; j
< count
; j
+= nr
) {
293 nr
= MIN2( currentsz
, count
- j
);
294 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
301 static void TAG(render_tri_strip_verts
)( GLcontext
*ctx
,
306 if (HAVE_TRI_STRIPS
) {
309 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
312 INIT(GL_TRIANGLE_STRIP
);
314 currentsz
= GET_CURRENT_VB_MAX_VERTS();
320 /* From here on emit even numbers of tris when wrapping over buffers:
322 dmasz
-= (dmasz
& 1);
323 currentsz
-= (currentsz
& 1);
325 for (j
= start
; j
+ 2 < count
; j
+= nr
- 2 ) {
326 nr
= MIN2( currentsz
, count
- j
);
327 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
334 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
339 static void TAG(render_tri_fan_verts
)( GLcontext
*ctx
,
347 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
350 INIT(GL_TRIANGLE_FAN
);
352 currentsz
= GET_CURRENT_VB_MAX_VERTS();
357 for (j
= start
+ 1 ; j
+ 1 < count
; j
+= nr
- 2 ) {
359 nr
= MIN2( currentsz
, count
- j
+ 1 );
360 tmp
= ALLOC_VERTS( nr
);
361 tmp
= TAG(emit_verts
)( ctx
, start
, 1, tmp
);
362 tmp
= TAG(emit_verts
)( ctx
, j
, nr
- 1, tmp
);
370 /* Could write code to emit these as indexed vertices (for the
371 * g400, for instance).
373 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
379 static void TAG(render_poly_verts
)( GLcontext
*ctx
,
387 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
392 currentsz
= GET_CURRENT_VB_MAX_VERTS();
397 for (j
= start
+ 1 ; j
+ 1 < count
; j
+= nr
- 2 ) {
399 nr
= MIN2( currentsz
, count
- j
+ 1 );
400 tmp
= ALLOC_VERTS( nr
);
401 tmp
= TAG(emit_verts
)( ctx
, start
, 1, tmp
);
402 tmp
= TAG(emit_verts
)( ctx
, j
, nr
- 1, tmp
);
408 else if (HAVE_TRI_FANS
&& ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
409 TAG(render_tri_fan_verts
)( ctx
, start
, count
, flags
);
411 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
416 static void TAG(render_quad_strip_verts
)( GLcontext
*ctx
,
423 if (HAVE_QUAD_STRIPS
) {
426 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
431 currentsz
= GET_CURRENT_VB_MAX_VERTS();
436 dmasz
-= (dmasz
& 2);
437 currentsz
-= (currentsz
& 2);
439 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
440 nr
= MIN2( currentsz
, count
- j
);
441 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
447 } else if (HAVE_TRI_STRIPS
&&
448 ctx
->Light
.ShadeModel
== GL_FLAT
&&
449 TNL_CONTEXT(ctx
)->vb
.ColorPtr
[0]->stride
) {
452 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
456 EMIT_INDEXED_VERTS( ctx
, start
, count
);
458 /* Simulate flat-shaded quadstrips using indexed vertices:
460 ELT_INIT( GL_TRIANGLES
);
462 currentsz
= GET_CURRENT_VB_MAX_ELTS();
464 /* Emit whole number of quads in total, and in each buffer.
467 count
-= (count
-start
) & 1;
468 currentsz
-= currentsz
& 1;
473 currentsz
= currentsz
/6*2;
476 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
477 nr
= MIN2( currentsz
, count
- j
);
479 GLint quads
= (nr
/2)-1;
481 ELTS_VARS( ALLOC_ELTS( quads
*6 ) );
483 for ( i
= j
-start
; i
< j
-start
+quads
*2 ; i
+=2 ) {
484 EMIT_TWO_ELTS( 0, (i
+0), (i
+1) );
485 EMIT_TWO_ELTS( 2, (i
+2), (i
+1) );
486 EMIT_TWO_ELTS( 4, (i
+3), (i
+2) );
499 /* Vertices won't fit in a single buffer or elts not
500 * available - should never happen.
502 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
506 else if (HAVE_TRI_STRIPS
) {
508 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
511 /* Emit smooth-shaded quadstrips as tristrips:
514 INIT( GL_TRIANGLE_STRIP
);
516 /* Emit whole number of quads in total, and in each buffer.
519 currentsz
= GET_CURRENT_VB_MAX_VERTS();
520 currentsz
-= currentsz
& 1;
521 count
-= (count
-start
) & 1;
527 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
528 nr
= MIN2( currentsz
, count
- j
);
529 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
536 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
542 static void TAG(render_quads_verts
)( GLcontext
*ctx
,
549 int dmasz
= (GET_SUBSEQUENT_VB_MAX_VERTS()/4) * 4;
555 /* Emit whole number of quads in total. dmasz is already a multiple
558 count
-= (count
-start
)%4;
560 currentsz
= (GET_CURRENT_VB_MAX_VERTS()/4) * 4;
564 for (j
= start
; j
< count
; j
+= nr
) {
565 nr
= MIN2( currentsz
, count
- j
);
566 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
570 else if (HAVE_ELTS
) {
571 /* Hardware doesn't have a quad primitive type -- try to
572 * simulate it using indexed vertices and the triangle
576 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
580 EMIT_INDEXED_VERTS( ctx
, start
, count
);
583 ELT_INIT( GL_TRIANGLES
);
584 currentsz
= GET_CURRENT_VB_MAX_ELTS();
586 /* Emit whole number of quads in total, and in each buffer.
589 count
-= (count
-start
) & 3;
590 currentsz
-= currentsz
& 3;
592 /* Adjust for rendering as triangles:
594 currentsz
= currentsz
/6*4;
600 for (j
= start
; j
< count
; j
+= nr
) {
601 nr
= MIN2( currentsz
, count
- j
);
605 ELTS_VARS( ALLOC_ELTS( quads
*6 ) );
607 for ( i
= j
-start
; i
< j
-start
+quads
*4 ; i
+=4 ) {
608 EMIT_TWO_ELTS( 0, (i
+0), (i
+1) );
609 EMIT_TWO_ELTS( 2, (i
+3), (i
+1) );
610 EMIT_TWO_ELTS( 4, (i
+2), (i
+3) );
621 else if (HAVE_TRIANGLES
) {
622 /* Hardware doesn't have a quad primitive type -- try to
623 * simulate it using triangle primitive. This is a win for
624 * gears, but is it useful in the broader world?
631 for (j
= start
; j
< count
-3; j
+= 4) {
632 void *tmp
= ALLOC_VERTS( 6 );
635 tmp
= EMIT_VERTS(ctx
, j
, 2, tmp
);
636 tmp
= EMIT_VERTS(ctx
, j
+ 3, 1, tmp
);
639 tmp
= EMIT_VERTS(ctx
, j
+ 1, 3, tmp
);
643 /* Vertices won't fit in a single buffer, should never happen.
645 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
650 static void TAG(render_noop
)( GLcontext
*ctx
,
660 static tnl_render_func
TAG(render_tab_verts
)[GL_POLYGON
+2] =
662 TAG(render_points_verts
),
663 TAG(render_lines_verts
),
664 TAG(render_line_loop_verts
),
665 TAG(render_line_strip_verts
),
666 TAG(render_triangles_verts
),
667 TAG(render_tri_strip_verts
),
668 TAG(render_tri_fan_verts
),
669 TAG(render_quads_verts
),
670 TAG(render_quad_strip_verts
),
671 TAG(render_poly_verts
),
676 /****************************************************************************
677 * Render elts using hardware indexed verts *
678 ****************************************************************************/
681 static void TAG(render_points_elts
)( GLcontext
*ctx
,
688 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
690 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
693 ELT_INIT( GL_POINTS
);
695 currentsz
= GET_CURRENT_VB_MAX_ELTS();
699 for (j
= start
; j
< count
; j
+= nr
) {
700 nr
= MIN2( currentsz
, count
- j
);
701 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
706 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
713 static void TAG(render_lines_elts
)( GLcontext
*ctx
,
720 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
722 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
725 ELT_INIT( GL_LINES
);
727 /* Emit whole number of lines in total and in each buffer:
729 count
-= (count
-start
) & 1;
730 currentsz
-= currentsz
& 1;
733 currentsz
= GET_CURRENT_VB_MAX_ELTS();
737 for (j
= start
; j
< count
; j
+= nr
) {
738 nr
= MIN2( currentsz
, count
- j
);
739 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
744 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
750 static void TAG(render_line_strip_elts
)( GLcontext
*ctx
,
755 if (HAVE_LINE_STRIPS
) {
757 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
759 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
762 FLUSH(); /* always a new primitive */
763 ELT_INIT( GL_LINE_STRIP
);
765 currentsz
= GET_CURRENT_VB_MAX_ELTS();
769 for (j
= start
; j
+ 1 < count
; j
+= nr
- 1 ) {
770 nr
= MIN2( currentsz
, count
- j
);
771 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
776 /* TODO: Try to emit as indexed lines.
778 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
784 static void TAG(render_line_loop_elts
)( GLcontext
*ctx
,
789 if (HAVE_LINE_STRIPS
) {
791 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
793 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
797 ELT_INIT( GL_LINE_STRIP
);
799 if (flags
& PRIM_BEGIN
)
804 currentsz
= GET_CURRENT_VB_MAX_ELTS();
809 /* Ensure last vertex doesn't wrap:
815 for ( ; j
+ 1 < count
; j
+= nr
- 1 ) {
816 nr
= MIN2( currentsz
, count
- j
);
818 if (j
+ nr
>= count
&&
823 tmp
= ALLOC_ELTS(nr
+1);
824 tmp
= TAG(emit_elts
)( ctx
, elts
+j
, nr
, tmp
);
825 tmp
= TAG(emit_elts
)( ctx
, elts
+start
, 1, tmp
);
828 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
834 else if (start
+ 1 < count
&& (flags
& PRIM_END
)) {
837 tmp
= TAG(emit_elts
)( ctx
, elts
+start
+1, 1, tmp
);
838 tmp
= TAG(emit_elts
)( ctx
, elts
+start
, 1, tmp
);
843 /* TODO: Try to emit as indexed lines */
844 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
850 /* For verts, we still eliminate the copy from main memory to dma
851 * buffers. For elts, this is probably no better (worse?) than the
854 static void TAG(render_triangles_elts
)( GLcontext
*ctx
,
860 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
861 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS()/3*3;
866 ELT_INIT( GL_TRIANGLES
);
868 currentsz
= GET_CURRENT_VB_MAX_ELTS();
870 /* Emit whole number of tris in total. dmasz is already a multiple
873 count
-= (count
-start
)%3;
874 currentsz
-= currentsz
%3;
878 for (j
= start
; j
< count
; j
+= nr
) {
879 nr
= MIN2( currentsz
, count
- j
);
880 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
888 static void TAG(render_tri_strip_elts
)( GLcontext
*ctx
,
893 if (HAVE_TRI_STRIPS
) {
896 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
897 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
901 ELT_INIT( GL_TRIANGLE_STRIP
);
903 currentsz
= GET_CURRENT_VB_MAX_ELTS();
908 /* Keep the same winding over multiple buffers:
910 dmasz
-= (dmasz
& 1);
911 currentsz
-= (currentsz
& 1);
913 for (j
= start
; j
+ 2 < count
; j
+= nr
- 2 ) {
914 nr
= MIN2( currentsz
, count
- j
);
915 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
920 /* TODO: try to emit as indexed triangles */
921 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
926 static void TAG(render_tri_fan_elts
)( GLcontext
*ctx
,
933 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
935 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
939 ELT_INIT( GL_TRIANGLE_FAN
);
941 currentsz
= GET_CURRENT_VB_MAX_ELTS();
946 for (j
= start
+ 1 ; j
+ 1 < count
; j
+= nr
- 2 ) {
948 nr
= MIN2( currentsz
, count
- j
+ 1 );
949 tmp
= ALLOC_ELTS( nr
);
950 tmp
= TAG(emit_elts
)( ctx
, elts
+start
, 1, tmp
);
951 tmp
= TAG(emit_elts
)( ctx
, elts
+j
, nr
- 1, tmp
);
956 /* TODO: try to emit as indexed triangles */
957 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
963 static void TAG(render_poly_elts
)( GLcontext
*ctx
,
970 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
972 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
976 ELT_INIT( GL_POLYGON
);
978 currentsz
= GET_CURRENT_VB_MAX_ELTS();
983 for (j
= start
+ 1 ; j
+ 1 < count
; j
+= nr
- 2 ) {
985 nr
= MIN2( currentsz
, count
- j
+ 1 );
986 tmp
= ALLOC_ELTS( nr
);
987 tmp
= TAG(emit_elts
)( ctx
, elts
+start
, 1, tmp
);
988 tmp
= TAG(emit_elts
)( ctx
, elts
+j
, nr
- 1, tmp
);
992 } else if (HAVE_TRI_FANS
&& ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
993 TAG(render_tri_fan_verts
)( ctx
, start
, count
, flags
);
995 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
1000 static void TAG(render_quad_strip_elts
)( GLcontext
*ctx
,
1005 if (HAVE_QUAD_STRIPS
&& 0) {
1007 else if (HAVE_TRI_STRIPS
) {
1009 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
1010 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
1015 currentsz
= GET_CURRENT_VB_MAX_ELTS();
1017 /* Emit whole number of quads in total, and in each buffer.
1020 count
-= (count
-start
) & 1;
1021 currentsz
-= currentsz
& 1;
1026 if (ctx
->Light
.ShadeModel
== GL_FLAT
) {
1027 ELT_INIT( GL_TRIANGLES
);
1029 currentsz
= currentsz
/6*2;
1032 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
1033 nr
= MIN2( currentsz
, count
- j
);
1038 GLint quads
= (nr
/2)-1;
1039 ELTS_VARS( ALLOC_ELTS( quads
*6 ) );
1041 for ( i
= j
-start
; i
< j
-start
+quads
; i
++, elts
+= 2 ) {
1042 EMIT_TWO_ELTS( 0, elts
[0], elts
[1] );
1043 EMIT_TWO_ELTS( 2, elts
[2], elts
[1] );
1044 EMIT_TWO_ELTS( 4, elts
[3], elts
[2] );
1055 ELT_INIT( GL_TRIANGLE_STRIP
);
1057 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
1058 nr
= MIN2( currentsz
, count
- j
);
1059 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
1068 static void TAG(render_quads_elts
)( GLcontext
*ctx
,
1075 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
1076 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS()/4*4;
1081 ELT_INIT( GL_TRIANGLES
);
1083 currentsz
= GET_CURRENT_VB_MAX_ELTS()/4*4;
1085 count
-= (count
-start
)%4;
1090 for (j
= start
; j
< count
; j
+= nr
) {
1091 nr
= MIN2( currentsz
, count
- j
);
1092 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
1098 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
1099 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
1103 ELT_INIT( GL_TRIANGLES
);
1104 currentsz
= GET_CURRENT_VB_MAX_ELTS();
1106 /* Emit whole number of quads in total, and in each buffer.
1109 count
-= (count
-start
) & 3;
1110 currentsz
-= currentsz
& 3;
1112 /* Adjust for rendering as triangles:
1114 currentsz
= currentsz
/6*4;
1120 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
1121 nr
= MIN2( currentsz
, count
- j
);
1127 ELTS_VARS( ALLOC_ELTS( quads
* 6 ) );
1129 for ( i
= j
-start
; i
< j
-start
+quads
; i
++, elts
+= 4 ) {
1130 EMIT_TWO_ELTS( 0, elts
[0], elts
[1] );
1131 EMIT_TWO_ELTS( 2, elts
[3], elts
[1] );
1132 EMIT_TWO_ELTS( 4, elts
[2], elts
[3] );
1146 static tnl_render_func
TAG(render_tab_elts
)[GL_POLYGON
+2] =
1148 TAG(render_points_elts
),
1149 TAG(render_lines_elts
),
1150 TAG(render_line_loop_elts
),
1151 TAG(render_line_strip_elts
),
1152 TAG(render_triangles_elts
),
1153 TAG(render_tri_strip_elts
),
1154 TAG(render_tri_fan_elts
),
1155 TAG(render_quads_elts
),
1156 TAG(render_quad_strip_elts
),
1157 TAG(render_poly_elts
),
1167 /* Pre-check the primitives in the VB to prevent the need for
1168 * fallbacks later on.
1170 static GLboolean
TAG(validate_render
)( GLcontext
*ctx
,
1171 struct vertex_buffer
*VB
)
1175 if (VB
->ClipOrMask
& ~CLIP_CULL_BIT
)
1178 if (VB
->Elts
&& !HAVE_ELTS
)
1181 for (i
= 0 ; i
< VB
->PrimitiveCount
; i
++) {
1182 GLuint prim
= VB
->Primitive
[i
].mode
;
1183 GLuint count
= VB
->Primitive
[i
].count
;
1184 GLboolean ok
= GL_FALSE
;
1189 switch (prim
& PRIM_MODE_MASK
) {
1194 ok
= HAVE_LINES
&& !ctx
->Line
.StippleFlag
;
1197 ok
= HAVE_LINE_STRIPS
&& !ctx
->Line
.StippleFlag
;
1200 ok
= HAVE_LINE_STRIPS
&& !ctx
->Line
.StippleFlag
;
1203 ok
= HAVE_TRIANGLES
;
1205 case GL_TRIANGLE_STRIP
:
1206 ok
= HAVE_TRI_STRIPS
;
1208 case GL_TRIANGLE_FAN
:
1212 if (HAVE_POLYGONS
) {
1216 ok
= (HAVE_TRI_FANS
&& ctx
->Light
.ShadeModel
== GL_SMOOTH
);
1221 ok
= HAVE_TRI_STRIPS
;
1223 else if (HAVE_QUAD_STRIPS
) {
1225 } else if (HAVE_TRI_STRIPS
&&
1226 ctx
->Light
.ShadeModel
== GL_FLAT
&&
1227 VB
->ColorPtr
[0]->stride
!= 0) {
1229 ok
= (GLint
) count
< GET_SUBSEQUENT_VB_MAX_ELTS();
1236 ok
= HAVE_TRI_STRIPS
;
1241 } else if (HAVE_ELTS
) {
1242 ok
= (GLint
) count
< GET_SUBSEQUENT_VB_MAX_ELTS();
1245 ok
= HAVE_TRIANGLES
; /* flatshading is ok. */
1253 /* fprintf(stderr, "not ok %s\n", _mesa_lookup_enum_by_nr(prim & PRIM_MODE_MASK)); */