patch to import Jon Smirl's work from Bitkeeper
[mesa.git] / src / mesa / tnl_dd / t_dd_dmatmp2.h
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 4.0.3
5 *
6 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * Keith Whitwell <keith@tungstengraphics.com>
27 */
28
29
30 /* Template for render stages which build and emit vertices directly
31 * to fixed-size dma buffers. Useful for rendering strips and other
32 * native primitives where clipping and per-vertex tweaks such as
33 * those in t_dd_tritmp.h are not required.
34 *
35 */
36
37 #if !HAVE_TRIANGLES || !HAVE_POINTS || !HAVE_LINES
38 #error "must have points, lines & triangles to use render template"
39 #endif
40
41 #if !HAVE_TRI_STRIPS || !HAVE_TRI_FANS
42 #error "must have tri strip and fans to use render template"
43 #endif
44
45 #if !HAVE_LINE_STRIPS
46 #error "must have line strips to use render template"
47 #endif
48
49 #if !HAVE_POLYGONS
50 #error "must have polygons to use render template"
51 #endif
52
53 #if !HAVE_ELTS
54 #error "must have elts to use render template"
55 #endif
56
57
58 #ifndef EMIT_TWO_ELTS
59 #define EMIT_TWO_ELTS( dest, offset, elt0, elt1 ) \
60 do { \
61 (dest)[offset] = (elt0); \
62 (dest)[offset+1] = (elt1); \
63 } while (0)
64 #endif
65
66
67 /**********************************************************************/
68 /* Render whole begin/end objects */
69 /**********************************************************************/
70
71
72 static ELT_TYPE *TAG(emit_elts)( GLcontext *ctx,
73 ELT_TYPE *dest,
74 GLuint *elts, GLuint nr )
75 {
76 GLint i;
77 LOCAL_VARS;
78
79 for ( i = 0 ; i+1 < nr ; i+=2, elts += 2 ) {
80 EMIT_TWO_ELTS( dest, 0, elts[0], elts[1] );
81 dest += 2;
82 }
83 if (i < nr) {
84 EMIT_ELT( dest, 0, elts[0] );
85 dest += 1;
86 }
87
88 return dest;
89 }
90
91 static ELT_TYPE *TAG(emit_consecutive_elts)( GLcontext *ctx,
92 ELT_TYPE *dest,
93 GLuint start, GLuint nr )
94 {
95 GLint i;
96 LOCAL_VARS;
97
98 for ( i = 0 ; i+1 < nr ; i+=2, start += 2 ) {
99 EMIT_TWO_ELTS( dest, 0, start, start+1 );
100 dest += 2;
101 }
102 if (i < nr) {
103 EMIT_ELT( dest, 0, start );
104 dest += 1;
105 }
106
107 return dest;
108 }
109
110 /***********************************************************************
111 * Render non-indexed primitives.
112 ***********************************************************************/
113
114
115
116 static void TAG(render_points_verts)( GLcontext *ctx,
117 GLuint start,
118 GLuint count,
119 GLuint flags )
120 {
121 if (start < count) {
122 LOCAL_VARS;
123 if (0) fprintf(stderr, "%s\n", __FUNCTION__);
124 EMIT_PRIM( ctx, GL_POINTS, HW_POINTS, start, count );
125 }
126 }
127
128 static void TAG(render_lines_verts)( GLcontext *ctx,
129 GLuint start,
130 GLuint count,
131 GLuint flags )
132 {
133 LOCAL_VARS;
134 if (0) fprintf(stderr, "%s\n", __FUNCTION__);
135 count -= (count-start) & 1;
136
137 if (start+1 >= count)
138 return;
139
140 if ((flags & PRIM_BEGIN) && ctx->Line.StippleFlag) {
141 RESET_STIPPLE();
142 AUTO_STIPPLE( GL_TRUE );
143 }
144
145 EMIT_PRIM( ctx, GL_LINES, HW_LINES, start, count );
146
147 if ((flags & PRIM_END) && ctx->Line.StippleFlag)
148 AUTO_STIPPLE( GL_FALSE );
149 }
150
151
152 static void TAG(render_line_strip_verts)( GLcontext *ctx,
153 GLuint start,
154 GLuint count,
155 GLuint flags )
156 {
157 LOCAL_VARS;
158 if (0) fprintf(stderr, "%s\n", __FUNCTION__);
159
160 if (start+1 >= count)
161 return;
162
163 if ((flags & PRIM_BEGIN) && ctx->Line.StippleFlag)
164 RESET_STIPPLE();
165
166
167 if (PREFER_DISCRETE_ELT_PRIM( count-start, HW_LINES ))
168 {
169 int dmasz = GET_MAX_HW_ELTS();
170 GLuint j, nr;
171
172 ELT_INIT( GL_LINES, HW_LINES );
173
174 /* Emit whole number of lines in each full buffer.
175 */
176 dmasz = dmasz/2;
177
178
179 for (j = start; j + 1 < count; j += nr - 1 ) {
180 ELT_TYPE *dest;
181 GLint i;
182
183 nr = MIN2( dmasz, count - j );
184 dest = ALLOC_ELTS( (nr-1)*2 );
185
186 for ( i = j ; i+1 < j+nr ; i+=1 ) {
187 EMIT_TWO_ELTS( dest, 0, (i+0), (i+1) );
188 dest += 2;
189 }
190
191 CLOSE_ELTS();
192 }
193 }
194 else
195 EMIT_PRIM( ctx, GL_LINE_STRIP, HW_LINE_STRIP, start, count );
196 }
197
198
199 static void TAG(render_line_loop_verts)( GLcontext *ctx,
200 GLuint start,
201 GLuint count,
202 GLuint flags )
203 {
204 LOCAL_VARS;
205 GLuint j, nr;
206 if (0) fprintf(stderr, "%s\n", __FUNCTION__);
207
208 if (flags & PRIM_BEGIN) {
209 j = start;
210 if (ctx->Line.StippleFlag)
211 RESET_STIPPLE( );
212 }
213 else
214 j = start + 1;
215
216 if (flags & PRIM_END) {
217
218 if (start+1 >= count)
219 return;
220
221 if (PREFER_DISCRETE_ELT_PRIM( count-start, HW_LINES )) {
222 int dmasz = GET_MAX_HW_ELTS();
223
224 ELT_INIT( GL_LINES, HW_LINES );
225
226 /* Emit whole number of lines in each full buffer.
227 */
228 dmasz = dmasz/2;
229
230 /* Ensure last vertex doesn't wrap:
231 */
232 dmasz--;
233
234 for (; j + 1 < count; ) {
235 GLint i;
236 ELT_TYPE *dest;
237
238 nr = MIN2( dmasz, count - j );
239 dest = ALLOC_ELTS( nr*2 ); /* allocs room for 1 more line */
240
241 for ( i = 0 ; i < nr - 1 ; i+=1 ) {
242 EMIT_TWO_ELTS( dest, 0, (j+i), (j+i+1) );
243 dest += 2;
244 }
245
246 j += nr - 1;
247
248 /* Emit 1 more line into space alloced above */
249 if (j + 1 >= count) {
250 EMIT_TWO_ELTS( dest, 0, (j), (start) );
251 dest += 2;
252 }
253
254 CLOSE_ELTS();
255 }
256 }
257 else
258 {
259 int dmasz = GET_MAX_HW_ELTS() - 1;
260
261 ELT_INIT( GL_LINE_STRIP, HW_LINE_STRIP );
262
263 for ( ; j + 1 < count; ) {
264 nr = MIN2( dmasz, count - j );
265 if (j + nr < count) {
266 ELT_TYPE *dest = ALLOC_ELTS( nr );
267 dest = TAG(emit_consecutive_elts)( ctx, dest, j, nr );
268 j += nr - 1;
269 CLOSE_ELTS();
270 }
271 else if (nr) {
272 ELT_TYPE *dest = ALLOC_ELTS( nr + 1 );
273 dest = TAG(emit_consecutive_elts)( ctx, dest, j, nr );
274 dest = TAG(emit_consecutive_elts)( ctx, dest, start, 1 );
275 j += nr;
276 CLOSE_ELTS();
277 }
278 }
279 }
280 } else {
281 TAG(render_line_strip_verts)( ctx, j, count, flags );
282 }
283 }
284
285
286 static void TAG(render_triangles_verts)( GLcontext *ctx,
287 GLuint start,
288 GLuint count,
289 GLuint flags )
290 {
291 LOCAL_VARS;
292 if (0) fprintf(stderr, "%s\n", __FUNCTION__);
293
294 count -= (count-start)%3;
295
296 if (start+2 >= count) {
297 return;
298 }
299
300 /* need a PREFER_DISCRETE_ELT_PRIM here too..
301 */
302 EMIT_PRIM( ctx, GL_TRIANGLES, HW_TRIANGLES, start, count );
303 }
304
305
306
307 static void TAG(render_tri_strip_verts)( GLcontext *ctx,
308 GLuint start,
309 GLuint count,
310 GLuint flags )
311 {
312 LOCAL_VARS;
313 if (0) fprintf(stderr, "%s\n", __FUNCTION__);
314
315 if (start + 2 >= count)
316 return;
317
318 if (PREFER_DISCRETE_ELT_PRIM( count-start, HW_TRIANGLES ))
319 {
320 int dmasz = GET_MAX_HW_ELTS();
321 int parity = 0;
322 GLuint j, nr;
323
324 ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
325
326 if (flags & PRIM_PARITY)
327 parity = 1;
328
329 /* Emit even number of tris in each full buffer.
330 */
331 dmasz = dmasz/3;
332 dmasz -= dmasz & 1;
333
334 for (j = start; j + 2 < count; j += nr - 2 ) {
335 ELT_TYPE *dest;
336 GLint i;
337
338 nr = MIN2( dmasz, count - j );
339 dest = ALLOC_ELTS( (nr-2)*3 );
340
341 for ( i = j ; i+2 < j+nr ; i++, parity^=1 ) {
342 EMIT_ELT( dest, 0, (i+0+parity) );
343 EMIT_ELT( dest, 1, (i+1-parity) );
344 EMIT_ELT( dest, 2, (i+2) );
345 dest += 3;
346 }
347
348 CLOSE_ELTS();
349 }
350 }
351 else if ((flags & PRIM_PARITY) == 0)
352 EMIT_PRIM( ctx, GL_TRIANGLE_STRIP, HW_TRIANGLE_STRIP_0, start, count );
353 else if (HAVE_TRI_STRIP_1)
354 EMIT_PRIM( ctx, GL_TRIANGLE_STRIP, HW_TRIANGLE_STRIP_1, start, count );
355 else {
356 /* Emit the first triangle with elts, then the rest as a regular strip.
357 * TODO: Make this unlikely in t_imm_api.c
358 */
359 ELT_TYPE *dest;
360
361 ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
362 dest = ALLOC_ELTS( 3 );
363 EMIT_ELT( dest, 0, (start+1) );
364 EMIT_ELT( dest, 1, (start+0) );
365 EMIT_ELT( dest, 2, (start+2) );
366 dest += 3;
367 CLOSE_ELTS();
368
369 start++;
370 if (start + 2 >= count)
371 return;
372
373 EMIT_PRIM( ctx, GL_TRIANGLE_STRIP, HW_TRIANGLE_STRIP_0, start,
374 count );
375 }
376 }
377
378 static void TAG(render_tri_fan_verts)( GLcontext *ctx,
379 GLuint start,
380 GLuint count,
381 GLuint flags )
382 {
383 LOCAL_VARS;
384 if (0) fprintf(stderr, "%s\n", __FUNCTION__);
385
386 if (start+2 >= count)
387 return;
388
389 if (PREFER_DISCRETE_ELT_PRIM( count-start, HW_TRIANGLES ))
390 {
391 int dmasz = GET_MAX_HW_ELTS();
392 GLuint j, nr;
393
394 ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
395
396 dmasz = dmasz/3;
397
398 for (j = start + 1; j + 1 < count; j += nr - 1 ) {
399 ELT_TYPE *dest;
400 GLint i;
401
402 nr = MIN2( dmasz, count - j );
403 dest = ALLOC_ELTS( (nr-1)*3 );
404
405 for ( i = j ; i+1 < j+nr ; i++ ) {
406 EMIT_ELT( dest, 0, (start) );
407 EMIT_ELT( dest, 1, (i) );
408 EMIT_ELT( dest, 2, (i+1) );
409 dest += 3;
410 }
411
412 CLOSE_ELTS();
413 }
414 }
415 else {
416 EMIT_PRIM( ctx, GL_TRIANGLE_FAN, HW_TRIANGLE_FAN, start, count );
417 }
418 }
419
420
421 static void TAG(render_poly_verts)( GLcontext *ctx,
422 GLuint start,
423 GLuint count,
424 GLuint flags )
425 {
426 LOCAL_VARS;
427 if (0) fprintf(stderr, "%s\n", __FUNCTION__);
428
429 if (start+2 >= count)
430 return;
431
432 EMIT_PRIM( ctx, GL_POLYGON, HW_POLYGON, start, count );
433 }
434
435 static void TAG(render_quad_strip_verts)( GLcontext *ctx,
436 GLuint start,
437 GLuint count,
438 GLuint flags )
439 {
440 LOCAL_VARS;
441 if (0) fprintf(stderr, "%s\n", __FUNCTION__);
442
443 count -= (count-start) & 1;
444
445 if (start+3 >= count)
446 return;
447
448 if (HAVE_QUAD_STRIPS) {
449 EMIT_PRIM( ctx, GL_QUAD_STRIP, HW_QUAD_STRIP, start, count );
450 }
451 else if (ctx->_TriangleCaps & DD_FLATSHADE) {
452 LOCAL_VARS;
453 int dmasz = GET_MAX_HW_ELTS();
454 GLuint j, nr;
455
456 ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
457
458 /* Emit whole number of quads in total, and in each buffer.
459 */
460 dmasz = (dmasz/6)*2;
461
462 for (j = start; j + 3 < count; j += nr - 2 ) {
463 ELT_TYPE *dest;
464 GLint quads, i;
465
466 nr = MIN2( dmasz, count - j );
467 quads = (nr/2)-1;
468 dest = ALLOC_ELTS( quads*6 );
469
470 for ( i = j ; i < j+quads*2 ; i+=2 ) {
471 EMIT_TWO_ELTS( dest, 0, (i+0), (i+1) );
472 EMIT_TWO_ELTS( dest, 2, (i+2), (i+1) );
473 EMIT_TWO_ELTS( dest, 4, (i+3), (i+2) );
474 dest += 6;
475 }
476
477 CLOSE_ELTS();
478 }
479 }
480 else {
481 EMIT_PRIM( ctx, GL_TRIANGLE_STRIP, HW_TRIANGLE_STRIP_0, start, count );
482 }
483 }
484
485
486 static void TAG(render_quads_verts)( GLcontext *ctx,
487 GLuint start,
488 GLuint count,
489 GLuint flags )
490 {
491 LOCAL_VARS;
492 if (0) fprintf(stderr, "%s\n", __FUNCTION__);
493 count -= (count-start)%4;
494
495 if (start+3 >= count)
496 return;
497
498 if (HAVE_QUADS) {
499 EMIT_PRIM( ctx, HW_QUADS, GL_QUADS, start, count );
500 }
501 else {
502 /* Hardware doesn't have a quad primitive type -- simulate it
503 * using indexed vertices and the triangle primitive:
504 */
505 LOCAL_VARS;
506 int dmasz = GET_MAX_HW_ELTS();
507 GLuint j, nr;
508
509 ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
510
511 /* Adjust for rendering as triangles:
512 */
513 dmasz = (dmasz/6)*4;
514
515 for (j = start; j < count; j += nr ) {
516 ELT_TYPE *dest;
517 GLint quads, i;
518
519 nr = MIN2( dmasz, count - j );
520 quads = nr/4;
521 dest = ALLOC_ELTS( quads*6 );
522
523 for ( i = j ; i < j+quads*4 ; i+=4 ) {
524 EMIT_TWO_ELTS( dest, 0, (i+0), (i+1) );
525 EMIT_TWO_ELTS( dest, 2, (i+3), (i+1) );
526 EMIT_TWO_ELTS( dest, 4, (i+2), (i+3) );
527 dest += 6;
528 }
529
530 CLOSE_ELTS();
531 }
532 }
533 }
534
535 static void TAG(render_noop)( GLcontext *ctx,
536 GLuint start,
537 GLuint count,
538 GLuint flags )
539 {
540 }
541
542
543
544
545 static render_func TAG(render_tab_verts)[GL_POLYGON+2] =
546 {
547 TAG(render_points_verts),
548 TAG(render_lines_verts),
549 TAG(render_line_loop_verts),
550 TAG(render_line_strip_verts),
551 TAG(render_triangles_verts),
552 TAG(render_tri_strip_verts),
553 TAG(render_tri_fan_verts),
554 TAG(render_quads_verts),
555 TAG(render_quad_strip_verts),
556 TAG(render_poly_verts),
557 TAG(render_noop),
558 };
559
560
561 /****************************************************************************
562 * Render elts using hardware indexed verts *
563 ****************************************************************************/
564
565 static void TAG(render_points_elts)( GLcontext *ctx,
566 GLuint start,
567 GLuint count,
568 GLuint flags )
569 {
570 LOCAL_VARS;
571 int dmasz = GET_MAX_HW_ELTS();
572 GLuint *elts = GET_MESA_ELTS();
573 GLuint j, nr;
574 ELT_TYPE *dest;
575
576 ELT_INIT( GL_POINTS, HW_POINTS );
577
578 for (j = start; j < count; j += nr ) {
579 nr = MIN2( dmasz, count - j );
580 dest = ALLOC_ELTS( nr );
581 dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
582 CLOSE_ELTS();
583 }
584 }
585
586
587
588 static void TAG(render_lines_elts)( GLcontext *ctx,
589 GLuint start,
590 GLuint count,
591 GLuint flags )
592 {
593 LOCAL_VARS;
594 int dmasz = GET_MAX_HW_ELTS();
595 GLuint *elts = GET_MESA_ELTS();
596 GLuint j, nr;
597 ELT_TYPE *dest;
598
599 if (start+1 >= count)
600 return;
601
602 if ((flags & PRIM_BEGIN) && ctx->Line.StippleFlag) {
603 RESET_STIPPLE();
604 AUTO_STIPPLE( GL_TRUE );
605 }
606
607 ELT_INIT( GL_LINES, HW_LINES );
608
609 /* Emit whole number of lines in total and in each buffer:
610 */
611 count -= (count-start) & 1;
612 dmasz -= dmasz & 1;
613
614 for (j = start; j < count; j += nr ) {
615 nr = MIN2( dmasz, count - j );
616 dest = ALLOC_ELTS( nr );
617 dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
618 CLOSE_ELTS();
619 }
620
621 if ((flags & PRIM_END) && ctx->Line.StippleFlag)
622 AUTO_STIPPLE( GL_FALSE );
623 }
624
625
626 static void TAG(render_line_strip_elts)( GLcontext *ctx,
627 GLuint start,
628 GLuint count,
629 GLuint flags )
630 {
631 LOCAL_VARS;
632 int dmasz = GET_MAX_HW_ELTS();
633 GLuint *elts = GET_MESA_ELTS();
634 GLuint j, nr;
635 ELT_TYPE *dest;
636
637 if (start+1 >= count)
638 return;
639
640 ELT_INIT( GL_LINE_STRIP, HW_LINE_STRIP );
641
642 if ((flags & PRIM_BEGIN) && ctx->Line.StippleFlag)
643 RESET_STIPPLE();
644
645 for (j = start; j + 1 < count; j += nr - 1 ) {
646 nr = MIN2( dmasz, count - j );
647 dest = ALLOC_ELTS( nr );
648 dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
649 CLOSE_ELTS();
650 }
651 }
652
653
654 static void TAG(render_line_loop_elts)( GLcontext *ctx,
655 GLuint start,
656 GLuint count,
657 GLuint flags )
658 {
659 LOCAL_VARS;
660 int dmasz = GET_MAX_HW_ELTS();
661 GLuint *elts = GET_MESA_ELTS();
662 GLuint j, nr;
663 ELT_TYPE *dest;
664
665 if (0) fprintf(stderr, "%s\n", __FUNCTION__);
666
667 if (flags & PRIM_BEGIN)
668 j = start;
669 else
670 j = start + 1;
671
672
673 if (flags & PRIM_END) {
674 if (start+1 >= count)
675 return;
676 }
677 else {
678 if (j+1 >= count)
679 return;
680 }
681
682 ELT_INIT( GL_LINE_STRIP, HW_LINE_STRIP );
683
684 if ((flags & PRIM_BEGIN) && ctx->Line.StippleFlag)
685 RESET_STIPPLE();
686
687
688 /* Ensure last vertex doesn't wrap:
689 */
690 dmasz--;
691
692 for ( ; j + 1 < count; ) {
693 nr = MIN2( dmasz, count - j );
694 dest = ALLOC_ELTS( nr+1 ); /* Reserve possible space for last elt */
695 dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
696 j += nr - 1;
697 if (j + 1 >= count && (flags & PRIM_END)) {
698 dest = TAG(emit_elts)( ctx, dest, elts+start, 1 );
699 }
700 CLOSE_ELTS();
701 }
702 }
703
704
705 static void TAG(render_triangles_elts)( GLcontext *ctx,
706 GLuint start,
707 GLuint count,
708 GLuint flags )
709 {
710 LOCAL_VARS;
711 GLuint *elts = GET_MESA_ELTS();
712 int dmasz = GET_MAX_HW_ELTS()/3*3;
713 GLuint j, nr;
714 ELT_TYPE *dest;
715
716 if (start+2 >= count)
717 return;
718
719 ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
720
721
722 /* Emit whole number of tris in total. dmasz is already a multiple
723 * of 3.
724 */
725 count -= (count-start)%3;
726
727 for (j = start; j < count; j += nr) {
728 nr = MIN2( dmasz, count - j );
729 dest = ALLOC_ELTS( nr );
730 dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
731 CLOSE_ELTS();
732 }
733 }
734
735
736
737 static void TAG(render_tri_strip_elts)( GLcontext *ctx,
738 GLuint start,
739 GLuint count,
740 GLuint flags )
741 {
742 LOCAL_VARS;
743 GLuint j, nr;
744 GLuint *elts = GET_MESA_ELTS();
745 int dmasz = GET_MAX_HW_ELTS();
746 ELT_TYPE *dest;
747
748 if (start+2 >= count)
749 return;
750
751 ELT_INIT( GL_TRIANGLE_STRIP, HW_TRIANGLE_STRIP_0 );
752
753 /* Keep the same winding over multiple buffers:
754 */
755 dmasz -= (dmasz & 1);
756
757 for (j = start ; j + 2 < count; j += nr - 2 ) {
758 nr = MIN2( dmasz, count - j );
759
760 if (flags & PRIM_PARITY) {
761 dest = ALLOC_ELTS( nr );
762 dest = TAG(emit_elts)( ctx, dest, elts+j, 1 );
763 dest = TAG(emit_elts)( ctx, dest, elts+j, nr-1 );
764 nr--; flags &= ~PRIM_PARITY;
765 CLOSE_ELTS();
766 }
767 else {
768 dest = ALLOC_ELTS( nr );
769 dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
770 CLOSE_ELTS();
771 }
772 }
773 }
774
775 static void TAG(render_tri_fan_elts)( GLcontext *ctx,
776 GLuint start,
777 GLuint count,
778 GLuint flags )
779 {
780 LOCAL_VARS;
781 GLuint *elts = GET_MESA_ELTS();
782 GLuint j, nr;
783 int dmasz = GET_MAX_HW_ELTS();
784 ELT_TYPE *dest;
785
786 if (start+2 >= count)
787 return;
788
789 ELT_INIT( GL_TRIANGLE_FAN, HW_TRIANGLE_FAN );
790
791 for (j = start + 1 ; j + 1 < count; j += nr - 1 ) {
792 nr = MIN2( dmasz, count - j + 1 );
793 dest = ALLOC_ELTS( nr );
794 dest = TAG(emit_elts)( ctx, dest, elts+start, 1 );
795 dest = TAG(emit_elts)( ctx, dest, elts+j, nr - 1 );
796 CLOSE_ELTS();
797 }
798 }
799
800
801 static void TAG(render_poly_elts)( GLcontext *ctx,
802 GLuint start,
803 GLuint count,
804 GLuint flags )
805 {
806 LOCAL_VARS;
807 GLuint *elts = GET_MESA_ELTS();
808 GLuint j, nr;
809 int dmasz = GET_MAX_HW_ELTS();
810 ELT_TYPE *dest;
811
812 if (start+2 >= count)
813 return;
814
815 ELT_INIT( GL_POLYGON, HW_POLYGON );
816
817 for (j = start + 1 ; j + 1 < count ; j += nr - 1 ) {
818 nr = MIN2( dmasz, count - j + 1 );
819 dest = ALLOC_ELTS( nr );
820 dest = TAG(emit_elts)( ctx, dest, elts+start, 1 );
821 dest = TAG(emit_elts)( ctx, dest, elts+j, nr - 1 );
822 CLOSE_ELTS();
823 }
824 }
825
826 static void TAG(render_quad_strip_elts)( GLcontext *ctx,
827 GLuint start,
828 GLuint count,
829 GLuint flags )
830 {
831 if (start+3 >= count)
832 return;
833
834 if (HAVE_QUAD_STRIPS && 0) {
835 }
836 else {
837 LOCAL_VARS;
838 GLuint *elts = GET_MESA_ELTS();
839 int dmasz = GET_MAX_HW_ELTS();
840 GLuint j, nr;
841 ELT_TYPE *dest;
842
843 /* Emit whole number of quads in total, and in each buffer.
844 */
845 dmasz -= dmasz & 1;
846 count -= (count-start) & 1;
847
848 if (ctx->_TriangleCaps & DD_FLATSHADE) {
849 ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
850
851 dmasz = dmasz/6*2;
852
853 for (j = start; j + 3 < count; j += nr - 2 ) {
854 nr = MIN2( dmasz, count - j );
855
856 if (nr >= 4)
857 {
858 GLint quads = (nr/2)-1;
859 ELT_TYPE *dest = ALLOC_ELTS( quads*6 );
860 GLint i;
861
862 for ( i = j-start ; i < j-start+quads ; i++, elts += 2 ) {
863 EMIT_TWO_ELTS( dest, 0, elts[0], elts[1] );
864 EMIT_TWO_ELTS( dest, 2, elts[2], elts[1] );
865 EMIT_TWO_ELTS( dest, 4, elts[3], elts[2] );
866 dest += 6;
867 }
868
869 CLOSE_ELTS();
870 }
871 }
872 }
873 else {
874 ELT_INIT( GL_TRIANGLE_STRIP, HW_TRIANGLE_STRIP_0 );
875
876 for (j = start; j + 3 < count; j += nr - 2 ) {
877 nr = MIN2( dmasz, count - j );
878 dest = ALLOC_ELTS( nr );
879 dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
880 CLOSE_ELTS();
881 }
882 }
883 }
884 }
885
886
887 static void TAG(render_quads_elts)( GLcontext *ctx,
888 GLuint start,
889 GLuint count,
890 GLuint flags )
891 {
892 if (start+3 >= count)
893 return;
894
895 if (HAVE_QUADS && 0) {
896 } else {
897 LOCAL_VARS;
898 GLuint *elts = GET_MESA_ELTS();
899 int dmasz = GET_MAX_HW_ELTS();
900 GLuint j, nr;
901
902 ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
903
904 /* Emit whole number of quads in total, and in each buffer.
905 */
906 dmasz -= dmasz & 3;
907 count -= (count-start) & 3;
908
909 /* Adjust for rendering as triangles:
910 */
911 dmasz = dmasz/6*4;
912
913 for (j = start; j + 3 < count; j += nr ) {
914 nr = MIN2( dmasz, count - j );
915
916 {
917 GLint quads = nr/4;
918 ELT_TYPE *dest = ALLOC_ELTS( quads * 6 );
919 GLint i;
920
921 for ( i = j-start ; i < j-start+quads ; i++, elts += 4 ) {
922 EMIT_TWO_ELTS( dest, 0, elts[0], elts[1] );
923 EMIT_TWO_ELTS( dest, 2, elts[3], elts[1] );
924 EMIT_TWO_ELTS( dest, 4, elts[2], elts[3] );
925 dest += 6;
926 }
927
928 CLOSE_ELTS();
929 }
930 }
931 }
932 }
933
934
935
936 static render_func TAG(render_tab_elts)[GL_POLYGON+2] =
937 {
938 TAG(render_points_elts),
939 TAG(render_lines_elts),
940 TAG(render_line_loop_elts),
941 TAG(render_line_strip_elts),
942 TAG(render_triangles_elts),
943 TAG(render_tri_strip_elts),
944 TAG(render_tri_fan_elts),
945 TAG(render_quads_elts),
946 TAG(render_quad_strip_elts),
947 TAG(render_poly_elts),
948 TAG(render_noop),
949 };