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
);
246 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
252 else if (start
+ 1 < count
&& (flags
& PRIM_END
)) {
254 tmp
= ALLOC_VERTS(2);
255 tmp
= TAG(emit_verts
)( ctx
, start
+1, 1, tmp
);
256 tmp
= TAG(emit_verts
)( ctx
, start
, 1, tmp
);
262 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
268 static void TAG(render_triangles_verts
)( GLcontext
*ctx
,
274 int dmasz
= (GET_SUBSEQUENT_VB_MAX_VERTS()/3) * 3;
280 currentsz
= (GET_CURRENT_VB_MAX_VERTS()/3) * 3;
282 /* Emit whole number of tris in total. dmasz is already a multiple
285 count
-= (count
-start
)%3;
290 for (j
= start
; j
< count
; j
+= nr
) {
291 nr
= MIN2( currentsz
, count
- j
);
292 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
299 static void TAG(render_tri_strip_verts
)( GLcontext
*ctx
,
304 if (HAVE_TRI_STRIPS
) {
307 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
310 INIT(GL_TRIANGLE_STRIP
);
312 currentsz
= GET_CURRENT_VB_MAX_VERTS();
318 /* From here on emit even numbers of tris when wrapping over buffers:
320 dmasz
-= (dmasz
& 1);
321 currentsz
-= (currentsz
& 1);
323 for (j
= start
; j
+ 2 < count
; j
+= nr
- 2 ) {
324 nr
= MIN2( currentsz
, count
- j
);
325 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
332 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
337 static void TAG(render_tri_fan_verts
)( GLcontext
*ctx
,
345 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
348 INIT(GL_TRIANGLE_FAN
);
350 currentsz
= GET_CURRENT_VB_MAX_VERTS();
355 for (j
= start
+ 1 ; j
+ 1 < count
; j
+= nr
- 2 ) {
357 nr
= MIN2( currentsz
, count
- j
+ 1 );
358 tmp
= ALLOC_VERTS( nr
);
359 tmp
= TAG(emit_verts
)( ctx
, start
, 1, tmp
);
360 tmp
= TAG(emit_verts
)( ctx
, j
, nr
- 1, tmp
);
367 /* Could write code to emit these as indexed vertices (for the
368 * g400, for instance).
370 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
376 static void TAG(render_poly_verts
)( GLcontext
*ctx
,
384 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
389 currentsz
= GET_CURRENT_VB_MAX_VERTS();
394 for (j
= start
+ 1 ; j
+ 1 < count
; j
+= nr
- 2 ) {
396 nr
= MIN2( currentsz
, count
- j
+ 1 );
397 tmp
= ALLOC_VERTS( nr
);
398 tmp
= TAG(emit_verts
)( ctx
, start
, 1, tmp
);
399 tmp
= TAG(emit_verts
)( ctx
, j
, nr
- 1, tmp
);
405 else if (HAVE_TRI_FANS
&& ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
406 TAG(render_tri_fan_verts
)( ctx
, start
, count
, flags
);
408 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
413 static void TAG(render_quad_strip_verts
)( GLcontext
*ctx
,
420 if (HAVE_QUAD_STRIPS
) {
423 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
428 currentsz
= GET_CURRENT_VB_MAX_VERTS();
433 dmasz
-= (dmasz
& 2);
434 currentsz
-= (currentsz
& 2);
436 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
437 nr
= MIN2( currentsz
, count
- j
);
438 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
444 } else if (HAVE_TRI_STRIPS
&&
445 ctx
->Light
.ShadeModel
== GL_FLAT
&&
446 TNL_CONTEXT(ctx
)->vb
.ColorPtr
[0]->stride
) {
449 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
453 EMIT_INDEXED_VERTS( ctx
, start
, count
);
455 /* Simulate flat-shaded quadstrips using indexed vertices:
457 ELT_INIT( GL_TRIANGLES
);
459 currentsz
= GET_CURRENT_VB_MAX_ELTS();
461 /* Emit whole number of quads in total, and in each buffer.
464 count
-= (count
-start
) & 1;
465 currentsz
-= currentsz
& 1;
470 currentsz
= currentsz
/6*2;
473 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
474 nr
= MIN2( currentsz
, count
- j
);
476 GLint quads
= (nr
/2)-1;
478 ELTS_VARS( ALLOC_ELTS( quads
*6 ) );
480 for ( i
= j
-start
; i
< j
-start
+quads
*2 ; i
+=2 ) {
481 EMIT_TWO_ELTS( 0, (i
+0), (i
+1) );
482 EMIT_TWO_ELTS( 2, (i
+2), (i
+1) );
483 EMIT_TWO_ELTS( 4, (i
+3), (i
+2) );
496 /* Vertices won't fit in a single buffer or elts not
497 * available - should never happen.
499 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
503 else if (HAVE_TRI_STRIPS
) {
505 int dmasz
= GET_SUBSEQUENT_VB_MAX_VERTS();
508 /* Emit smooth-shaded quadstrips as tristrips:
511 INIT( GL_TRIANGLE_STRIP
);
513 /* Emit whole number of quads in total, and in each buffer.
516 currentsz
= GET_CURRENT_VB_MAX_VERTS();
517 currentsz
-= currentsz
& 1;
518 count
-= (count
-start
) & 1;
524 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
525 nr
= MIN2( currentsz
, count
- j
);
526 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
533 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
539 static void TAG(render_quads_verts
)( GLcontext
*ctx
,
546 int dmasz
= (GET_SUBSEQUENT_VB_MAX_VERTS()/4) * 4;
552 /* Emit whole number of quads in total. dmasz is already a multiple
555 count
-= (count
-start
)%4;
557 currentsz
= (GET_CURRENT_VB_MAX_VERTS()/4) * 4;
561 for (j
= start
; j
< count
; j
+= nr
) {
562 nr
= MIN2( currentsz
, count
- j
);
563 TAG(emit_verts
)( ctx
, j
, nr
, ALLOC_VERTS(nr
) );
567 else if (HAVE_ELTS
) {
568 /* Hardware doesn't have a quad primitive type -- try to
569 * simulate it using indexed vertices and the triangle
573 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
577 EMIT_INDEXED_VERTS( ctx
, start
, count
);
580 ELT_INIT( GL_TRIANGLES
);
581 currentsz
= GET_CURRENT_VB_MAX_ELTS();
583 /* Emit whole number of quads in total, and in each buffer.
586 count
-= (count
-start
) & 3;
587 currentsz
-= currentsz
& 3;
589 /* Adjust for rendering as triangles:
591 currentsz
= currentsz
/6*4;
597 for (j
= start
; j
< count
; j
+= nr
) {
598 nr
= MIN2( currentsz
, count
- j
);
602 ELTS_VARS( ALLOC_ELTS( quads
*6 ) );
604 for ( i
= j
-start
; i
< j
-start
+quads
*4 ; i
+=4 ) {
605 EMIT_TWO_ELTS( 0, (i
+0), (i
+1) );
606 EMIT_TWO_ELTS( 2, (i
+3), (i
+1) );
607 EMIT_TWO_ELTS( 4, (i
+2), (i
+3) );
618 else if (HAVE_TRIANGLES
) {
619 /* Hardware doesn't have a quad primitive type -- try to
620 * simulate it using triangle primitive. This is a win for
621 * gears, but is it useful in the broader world?
628 for (j
= start
; j
< count
-3; j
+= 4) {
629 void *tmp
= ALLOC_VERTS( 6 );
632 tmp
= EMIT_VERTS(ctx
, j
, 2, tmp
);
633 tmp
= EMIT_VERTS(ctx
, j
+ 3, 1, tmp
);
636 tmp
= EMIT_VERTS(ctx
, j
+ 1, 3, tmp
);
640 /* Vertices won't fit in a single buffer, should never happen.
642 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
647 static void TAG(render_noop
)( GLcontext
*ctx
,
657 static tnl_render_func
TAG(render_tab_verts
)[GL_POLYGON
+2] =
659 TAG(render_points_verts
),
660 TAG(render_lines_verts
),
661 TAG(render_line_loop_verts
),
662 TAG(render_line_strip_verts
),
663 TAG(render_triangles_verts
),
664 TAG(render_tri_strip_verts
),
665 TAG(render_tri_fan_verts
),
666 TAG(render_quads_verts
),
667 TAG(render_quad_strip_verts
),
668 TAG(render_poly_verts
),
673 /****************************************************************************
674 * Render elts using hardware indexed verts *
675 ****************************************************************************/
678 static void TAG(render_points_elts
)( GLcontext
*ctx
,
685 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
687 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
690 ELT_INIT( GL_POINTS
);
692 currentsz
= GET_CURRENT_VB_MAX_ELTS();
696 for (j
= start
; j
< count
; j
+= nr
) {
697 nr
= MIN2( currentsz
, count
- j
);
698 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
703 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
710 static void TAG(render_lines_elts
)( GLcontext
*ctx
,
717 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
719 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
722 ELT_INIT( GL_LINES
);
724 /* Emit whole number of lines in total and in each buffer:
726 count
-= (count
-start
) & 1;
727 currentsz
-= currentsz
& 1;
730 currentsz
= GET_CURRENT_VB_MAX_ELTS();
734 for (j
= start
; j
< count
; j
+= nr
) {
735 nr
= MIN2( currentsz
, count
- j
);
736 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
741 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
747 static void TAG(render_line_strip_elts
)( GLcontext
*ctx
,
752 if (HAVE_LINE_STRIPS
) {
754 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
756 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
759 FLUSH(); /* always a new primitive */
760 ELT_INIT( GL_LINE_STRIP
);
762 currentsz
= GET_CURRENT_VB_MAX_ELTS();
766 for (j
= start
; j
+ 1 < count
; j
+= nr
- 1 ) {
767 nr
= MIN2( currentsz
, count
- j
);
768 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
773 /* TODO: Try to emit as indexed lines.
775 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
781 static void TAG(render_line_loop_elts
)( GLcontext
*ctx
,
786 if (HAVE_LINE_STRIPS
) {
788 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
790 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
794 ELT_INIT( GL_LINE_STRIP
);
796 if (flags
& PRIM_BEGIN
)
801 currentsz
= GET_CURRENT_VB_MAX_ELTS();
806 /* Ensure last vertex doesn't wrap:
812 for ( ; j
+ 1 < count
; j
+= nr
- 1 ) {
813 nr
= MIN2( currentsz
, count
- j
);
815 if (j
+ nr
>= count
&&
820 tmp
= ALLOC_ELTS(nr
+1);
821 tmp
= TAG(emit_elts
)( ctx
, elts
+j
, nr
, tmp
);
822 tmp
= TAG(emit_elts
)( ctx
, elts
+start
, 1, tmp
);
825 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
831 else if (start
+ 1 < count
&& (flags
& PRIM_END
)) {
834 tmp
= TAG(emit_elts
)( ctx
, elts
+start
+1, 1, tmp
);
835 tmp
= TAG(emit_elts
)( ctx
, elts
+start
, 1, tmp
);
840 /* TODO: Try to emit as indexed lines */
841 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
847 /* For verts, we still eliminate the copy from main memory to dma
848 * buffers. For elts, this is probably no better (worse?) than the
851 static void TAG(render_triangles_elts
)( GLcontext
*ctx
,
857 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
858 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS()/3*3;
863 ELT_INIT( GL_TRIANGLES
);
865 currentsz
= GET_CURRENT_VB_MAX_ELTS();
867 /* Emit whole number of tris in total. dmasz is already a multiple
870 count
-= (count
-start
)%3;
871 currentsz
-= currentsz
%3;
875 for (j
= start
; j
< count
; j
+= nr
) {
876 nr
= MIN2( currentsz
, count
- j
);
877 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
885 static void TAG(render_tri_strip_elts
)( GLcontext
*ctx
,
890 if (HAVE_TRI_STRIPS
) {
893 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
894 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
898 ELT_INIT( GL_TRIANGLE_STRIP
);
900 currentsz
= GET_CURRENT_VB_MAX_ELTS();
905 /* Keep the same winding over multiple buffers:
907 dmasz
-= (dmasz
& 1);
908 currentsz
-= (currentsz
& 1);
910 for (j
= start
; j
+ 2 < count
; j
+= nr
- 2 ) {
911 nr
= MIN2( currentsz
, count
- j
);
912 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
917 /* TODO: try to emit as indexed triangles */
918 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
923 static void TAG(render_tri_fan_elts
)( GLcontext
*ctx
,
930 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
932 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
936 ELT_INIT( GL_TRIANGLE_FAN
);
938 currentsz
= GET_CURRENT_VB_MAX_ELTS();
943 for (j
= start
+ 1 ; j
+ 1 < count
; j
+= nr
- 2 ) {
945 nr
= MIN2( currentsz
, count
- j
+ 1 );
946 tmp
= ALLOC_ELTS( nr
);
947 tmp
= TAG(emit_elts
)( ctx
, elts
+start
, 1, tmp
);
948 tmp
= TAG(emit_elts
)( ctx
, elts
+j
, nr
- 1, tmp
);
953 /* TODO: try to emit as indexed triangles */
954 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
960 static void TAG(render_poly_elts
)( GLcontext
*ctx
,
967 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
969 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
973 ELT_INIT( GL_POLYGON
);
975 currentsz
= GET_CURRENT_VB_MAX_ELTS();
980 for (j
= start
+ 1 ; j
+ 1 < count
; j
+= nr
- 2 ) {
982 nr
= MIN2( currentsz
, count
- j
+ 1 );
983 tmp
= ALLOC_ELTS( nr
);
984 tmp
= TAG(emit_elts
)( ctx
, elts
+start
, 1, tmp
);
985 tmp
= TAG(emit_elts
)( ctx
, elts
+j
, nr
- 1, tmp
);
989 } else if (HAVE_TRI_FANS
&& ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
990 TAG(render_tri_fan_verts
)( ctx
, start
, count
, flags
);
992 fprintf(stderr
, "%s - cannot draw primitive\n", __FUNCTION__
);
997 static void TAG(render_quad_strip_elts
)( GLcontext
*ctx
,
1002 if (HAVE_QUAD_STRIPS
&& 0) {
1004 else if (HAVE_TRI_STRIPS
) {
1006 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
1007 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
1012 currentsz
= GET_CURRENT_VB_MAX_ELTS();
1014 /* Emit whole number of quads in total, and in each buffer.
1017 count
-= (count
-start
) & 1;
1018 currentsz
-= currentsz
& 1;
1023 if (ctx
->Light
.ShadeModel
== GL_FLAT
) {
1024 ELT_INIT( GL_TRIANGLES
);
1026 currentsz
= currentsz
/6*2;
1029 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
1030 nr
= MIN2( currentsz
, count
- j
);
1035 GLint quads
= (nr
/2)-1;
1036 ELTS_VARS( ALLOC_ELTS( quads
*6 ) );
1038 for ( i
= j
-start
; i
< j
-start
+quads
; i
++, elts
+= 2 ) {
1039 EMIT_TWO_ELTS( 0, elts
[0], elts
[1] );
1040 EMIT_TWO_ELTS( 2, elts
[2], elts
[1] );
1041 EMIT_TWO_ELTS( 4, elts
[3], elts
[2] );
1052 ELT_INIT( GL_TRIANGLE_STRIP
);
1054 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
1055 nr
= MIN2( currentsz
, count
- j
);
1056 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
1065 static void TAG(render_quads_elts
)( GLcontext
*ctx
,
1072 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
1073 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS()/4*4;
1078 ELT_INIT( GL_TRIANGLES
);
1080 currentsz
= GET_CURRENT_VB_MAX_ELTS()/4*4;
1082 count
-= (count
-start
)%4;
1087 for (j
= start
; j
< count
; j
+= nr
) {
1088 nr
= MIN2( currentsz
, count
- j
);
1089 TAG(emit_elts
)( ctx
, elts
+j
, nr
, ALLOC_ELTS(nr
) );
1095 GLuint
*elts
= TNL_CONTEXT(ctx
)->vb
.Elts
;
1096 int dmasz
= GET_SUBSEQUENT_VB_MAX_ELTS();
1100 ELT_INIT( GL_TRIANGLES
);
1101 currentsz
= GET_CURRENT_VB_MAX_ELTS();
1103 /* Emit whole number of quads in total, and in each buffer.
1106 count
-= (count
-start
) & 3;
1107 currentsz
-= currentsz
& 3;
1109 /* Adjust for rendering as triangles:
1111 currentsz
= currentsz
/6*4;
1117 for (j
= start
; j
+ 3 < count
; j
+= nr
- 2 ) {
1118 nr
= MIN2( currentsz
, count
- j
);
1124 ELTS_VARS( ALLOC_ELTS( quads
* 6 ) );
1126 for ( i
= j
-start
; i
< j
-start
+quads
; i
++, elts
+= 4 ) {
1127 EMIT_TWO_ELTS( 0, elts
[0], elts
[1] );
1128 EMIT_TWO_ELTS( 2, elts
[3], elts
[1] );
1129 EMIT_TWO_ELTS( 4, elts
[2], elts
[3] );
1143 static tnl_render_func
TAG(render_tab_elts
)[GL_POLYGON
+2] =
1145 TAG(render_points_elts
),
1146 TAG(render_lines_elts
),
1147 TAG(render_line_loop_elts
),
1148 TAG(render_line_strip_elts
),
1149 TAG(render_triangles_elts
),
1150 TAG(render_tri_strip_elts
),
1151 TAG(render_tri_fan_elts
),
1152 TAG(render_quads_elts
),
1153 TAG(render_quad_strip_elts
),
1154 TAG(render_poly_elts
),
1164 /* Pre-check the primitives in the VB to prevent the need for
1165 * fallbacks later on.
1167 static GLboolean
TAG(validate_render
)( GLcontext
*ctx
,
1168 struct vertex_buffer
*VB
)
1172 if (VB
->ClipOrMask
& ~CLIP_CULL_BIT
)
1175 if (VB
->Elts
&& !HAVE_ELTS
)
1178 for (i
= 0 ; i
< VB
->PrimitiveCount
; i
++) {
1179 GLuint prim
= VB
->Primitive
[i
].mode
;
1180 GLuint count
= VB
->Primitive
[i
].count
;
1181 GLboolean ok
= GL_FALSE
;
1186 switch (prim
& PRIM_MODE_MASK
) {
1191 ok
= HAVE_LINES
&& !ctx
->Line
.StippleFlag
;
1194 ok
= HAVE_LINE_STRIPS
&& !ctx
->Line
.StippleFlag
;
1197 ok
= HAVE_LINE_STRIPS
&& !ctx
->Line
.StippleFlag
;
1200 ok
= HAVE_TRIANGLES
;
1202 case GL_TRIANGLE_STRIP
:
1203 ok
= HAVE_TRI_STRIPS
;
1205 case GL_TRIANGLE_FAN
:
1209 if (HAVE_POLYGONS
) {
1213 ok
= (HAVE_TRI_FANS
&& ctx
->Light
.ShadeModel
== GL_SMOOTH
);
1218 ok
= HAVE_TRI_STRIPS
;
1220 else if (HAVE_QUAD_STRIPS
) {
1222 } else if (HAVE_TRI_STRIPS
&&
1223 ctx
->Light
.ShadeModel
== GL_FLAT
&&
1224 VB
->ColorPtr
[0]->stride
!= 0) {
1226 ok
= (GLint
) count
< GET_SUBSEQUENT_VB_MAX_ELTS();
1233 ok
= HAVE_TRI_STRIPS
;
1238 } else if (HAVE_ELTS
) {
1239 ok
= (GLint
) count
< GET_SUBSEQUENT_VB_MAX_ELTS();
1242 ok
= HAVE_TRIANGLES
; /* flatshading is ok. */
1250 /* fprintf(stderr, "not ok %s\n", _mesa_lookup_enum_by_nr(prim & PRIM_MODE_MASK)); */