Merge vtx-0-2-branch
[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 /* Emit even number of tris in each full buffer.
327 */
328 dmasz = dmasz/3;
329 dmasz -= dmasz & 1;
330
331 for (j = start; j + 2 < count; j += nr - 2 ) {
332 ELT_TYPE *dest;
333 GLint i;
334
335 nr = MIN2( dmasz, count - j );
336 dest = ALLOC_ELTS( (nr-2)*3 );
337
338 for ( i = j ; i+2 < j+nr ; i++, parity^=1 ) {
339 EMIT_ELT( dest, 0, (i+0+parity) );
340 EMIT_ELT( dest, 1, (i+1-parity) );
341 EMIT_ELT( dest, 2, (i+2) );
342 dest += 3;
343 }
344
345 CLOSE_ELTS();
346 }
347 }
348 else if (HAVE_TRI_STRIP_1)
349 EMIT_PRIM( ctx, GL_TRIANGLE_STRIP, HW_TRIANGLE_STRIP_1, start, count );
350 else {
351 /* Emit the first triangle with elts, then the rest as a regular strip.
352 * TODO: Make this unlikely in t_imm_api.c
353 */
354 ELT_TYPE *dest;
355
356 ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
357 dest = ALLOC_ELTS( 3 );
358 EMIT_ELT( dest, 0, (start+1) );
359 EMIT_ELT( dest, 1, (start+0) );
360 EMIT_ELT( dest, 2, (start+2) );
361 dest += 3;
362 CLOSE_ELTS();
363
364 start++;
365 if (start + 2 >= count)
366 return;
367
368 EMIT_PRIM( ctx, GL_TRIANGLE_STRIP, HW_TRIANGLE_STRIP_0, start,
369 count );
370 }
371 }
372
373 static void TAG(render_tri_fan_verts)( GLcontext *ctx,
374 GLuint start,
375 GLuint count,
376 GLuint flags )
377 {
378 LOCAL_VARS;
379 if (0) fprintf(stderr, "%s\n", __FUNCTION__);
380
381 if (start+2 >= count)
382 return;
383
384 if (PREFER_DISCRETE_ELT_PRIM( count-start, HW_TRIANGLES ))
385 {
386 int dmasz = GET_MAX_HW_ELTS();
387 GLuint j, nr;
388
389 ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
390
391 dmasz = dmasz/3;
392
393 for (j = start + 1; j + 1 < count; j += nr - 1 ) {
394 ELT_TYPE *dest;
395 GLint i;
396
397 nr = MIN2( dmasz, count - j );
398 dest = ALLOC_ELTS( (nr-1)*3 );
399
400 for ( i = j ; i+1 < j+nr ; i++ ) {
401 EMIT_ELT( dest, 0, (start) );
402 EMIT_ELT( dest, 1, (i) );
403 EMIT_ELT( dest, 2, (i+1) );
404 dest += 3;
405 }
406
407 CLOSE_ELTS();
408 }
409 }
410 else {
411 EMIT_PRIM( ctx, GL_TRIANGLE_FAN, HW_TRIANGLE_FAN, start, count );
412 }
413 }
414
415
416 static void TAG(render_poly_verts)( GLcontext *ctx,
417 GLuint start,
418 GLuint count,
419 GLuint flags )
420 {
421 LOCAL_VARS;
422 if (0) fprintf(stderr, "%s\n", __FUNCTION__);
423
424 if (start+2 >= count)
425 return;
426
427 EMIT_PRIM( ctx, GL_POLYGON, HW_POLYGON, start, count );
428 }
429
430 static void TAG(render_quad_strip_verts)( GLcontext *ctx,
431 GLuint start,
432 GLuint count,
433 GLuint flags )
434 {
435 LOCAL_VARS;
436 if (0) fprintf(stderr, "%s\n", __FUNCTION__);
437
438 count -= (count-start) & 1;
439
440 if (start+3 >= count)
441 return;
442
443 if (HAVE_QUAD_STRIPS) {
444 EMIT_PRIM( ctx, GL_QUAD_STRIP, HW_QUAD_STRIP, start, count );
445 }
446 else if (ctx->_TriangleCaps & DD_FLATSHADE) {
447 LOCAL_VARS;
448 int dmasz = GET_MAX_HW_ELTS();
449 GLuint j, nr;
450
451 ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
452
453 /* Emit whole number of quads in total, and in each buffer.
454 */
455 dmasz = (dmasz/6)*2;
456
457 for (j = start; j + 3 < count; j += nr - 2 ) {
458 ELT_TYPE *dest;
459 GLint quads, i;
460
461 nr = MIN2( dmasz, count - j );
462 quads = (nr/2)-1;
463 dest = ALLOC_ELTS( quads*6 );
464
465 for ( i = j ; i < j+quads*2 ; i+=2 ) {
466 EMIT_TWO_ELTS( dest, 0, (i+0), (i+1) );
467 EMIT_TWO_ELTS( dest, 2, (i+2), (i+1) );
468 EMIT_TWO_ELTS( dest, 4, (i+3), (i+2) );
469 dest += 6;
470 }
471
472 CLOSE_ELTS();
473 }
474 }
475 else {
476 EMIT_PRIM( ctx, GL_TRIANGLE_STRIP, HW_TRIANGLE_STRIP_0, start, count );
477 }
478 }
479
480
481 static void TAG(render_quads_verts)( GLcontext *ctx,
482 GLuint start,
483 GLuint count,
484 GLuint flags )
485 {
486 LOCAL_VARS;
487 if (0) fprintf(stderr, "%s\n", __FUNCTION__);
488 count -= (count-start)%4;
489
490 if (start+3 >= count)
491 return;
492
493 if (HAVE_QUADS) {
494 EMIT_PRIM( ctx, HW_QUADS, GL_QUADS, start, count );
495 }
496 else {
497 /* Hardware doesn't have a quad primitive type -- simulate it
498 * using indexed vertices and the triangle primitive:
499 */
500 LOCAL_VARS;
501 int dmasz = GET_MAX_HW_ELTS();
502 GLuint j, nr;
503
504 ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
505
506 /* Adjust for rendering as triangles:
507 */
508 dmasz = (dmasz/6)*4;
509
510 for (j = start; j < count; j += nr ) {
511 ELT_TYPE *dest;
512 GLint quads, i;
513
514 nr = MIN2( dmasz, count - j );
515 quads = nr/4;
516 dest = ALLOC_ELTS( quads*6 );
517
518 for ( i = j ; i < j+quads*4 ; i+=4 ) {
519 EMIT_TWO_ELTS( dest, 0, (i+0), (i+1) );
520 EMIT_TWO_ELTS( dest, 2, (i+3), (i+1) );
521 EMIT_TWO_ELTS( dest, 4, (i+2), (i+3) );
522 dest += 6;
523 }
524
525 CLOSE_ELTS();
526 }
527 }
528 }
529
530 static void TAG(render_noop)( GLcontext *ctx,
531 GLuint start,
532 GLuint count,
533 GLuint flags )
534 {
535 }
536
537
538
539
540 static render_func TAG(render_tab_verts)[GL_POLYGON+2] =
541 {
542 TAG(render_points_verts),
543 TAG(render_lines_verts),
544 TAG(render_line_loop_verts),
545 TAG(render_line_strip_verts),
546 TAG(render_triangles_verts),
547 TAG(render_tri_strip_verts),
548 TAG(render_tri_fan_verts),
549 TAG(render_quads_verts),
550 TAG(render_quad_strip_verts),
551 TAG(render_poly_verts),
552 TAG(render_noop),
553 };
554
555
556 /****************************************************************************
557 * Render elts using hardware indexed verts *
558 ****************************************************************************/
559
560 static void TAG(render_points_elts)( GLcontext *ctx,
561 GLuint start,
562 GLuint count,
563 GLuint flags )
564 {
565 LOCAL_VARS;
566 int dmasz = GET_MAX_HW_ELTS();
567 GLuint *elts = GET_MESA_ELTS();
568 GLuint j, nr;
569 ELT_TYPE *dest;
570
571 ELT_INIT( GL_POINTS, HW_POINTS );
572
573 for (j = start; j < count; j += nr ) {
574 nr = MIN2( dmasz, count - j );
575 dest = ALLOC_ELTS( nr );
576 dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
577 CLOSE_ELTS();
578 }
579 }
580
581
582
583 static void TAG(render_lines_elts)( GLcontext *ctx,
584 GLuint start,
585 GLuint count,
586 GLuint flags )
587 {
588 LOCAL_VARS;
589 int dmasz = GET_MAX_HW_ELTS();
590 GLuint *elts = GET_MESA_ELTS();
591 GLuint j, nr;
592 ELT_TYPE *dest;
593
594 if (start+1 >= count)
595 return;
596
597 if ((flags & PRIM_BEGIN) && ctx->Line.StippleFlag) {
598 RESET_STIPPLE();
599 AUTO_STIPPLE( GL_TRUE );
600 }
601
602 ELT_INIT( GL_LINES, HW_LINES );
603
604 /* Emit whole number of lines in total and in each buffer:
605 */
606 count -= (count-start) & 1;
607 dmasz -= dmasz & 1;
608
609 for (j = start; j < count; j += nr ) {
610 nr = MIN2( dmasz, count - j );
611 dest = ALLOC_ELTS( nr );
612 dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
613 CLOSE_ELTS();
614 }
615
616 if ((flags & PRIM_END) && ctx->Line.StippleFlag)
617 AUTO_STIPPLE( GL_FALSE );
618 }
619
620
621 static void TAG(render_line_strip_elts)( GLcontext *ctx,
622 GLuint start,
623 GLuint count,
624 GLuint flags )
625 {
626 LOCAL_VARS;
627 int dmasz = GET_MAX_HW_ELTS();
628 GLuint *elts = GET_MESA_ELTS();
629 GLuint j, nr;
630 ELT_TYPE *dest;
631
632 if (start+1 >= count)
633 return;
634
635 ELT_INIT( GL_LINE_STRIP, HW_LINE_STRIP );
636
637 if ((flags & PRIM_BEGIN) && ctx->Line.StippleFlag)
638 RESET_STIPPLE();
639
640 for (j = start; j + 1 < count; j += nr - 1 ) {
641 nr = MIN2( dmasz, count - j );
642 dest = ALLOC_ELTS( nr );
643 dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
644 CLOSE_ELTS();
645 }
646 }
647
648
649 static void TAG(render_line_loop_elts)( GLcontext *ctx,
650 GLuint start,
651 GLuint count,
652 GLuint flags )
653 {
654 LOCAL_VARS;
655 int dmasz = GET_MAX_HW_ELTS();
656 GLuint *elts = GET_MESA_ELTS();
657 GLuint j, nr;
658 ELT_TYPE *dest;
659
660 if (0) fprintf(stderr, "%s\n", __FUNCTION__);
661
662 if (flags & PRIM_BEGIN)
663 j = start;
664 else
665 j = start + 1;
666
667
668 if (flags & PRIM_END) {
669 if (start+1 >= count)
670 return;
671 }
672 else {
673 if (j+1 >= count)
674 return;
675 }
676
677 ELT_INIT( GL_LINE_STRIP, HW_LINE_STRIP );
678
679 if ((flags & PRIM_BEGIN) && ctx->Line.StippleFlag)
680 RESET_STIPPLE();
681
682
683 /* Ensure last vertex doesn't wrap:
684 */
685 dmasz--;
686
687 for ( ; j + 1 < count; ) {
688 nr = MIN2( dmasz, count - j );
689 dest = ALLOC_ELTS( nr+1 ); /* Reserve possible space for last elt */
690 dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
691 j += nr - 1;
692 if (j + 1 >= count && (flags & PRIM_END)) {
693 dest = TAG(emit_elts)( ctx, dest, elts+start, 1 );
694 }
695 CLOSE_ELTS();
696 }
697 }
698
699
700 static void TAG(render_triangles_elts)( GLcontext *ctx,
701 GLuint start,
702 GLuint count,
703 GLuint flags )
704 {
705 LOCAL_VARS;
706 GLuint *elts = GET_MESA_ELTS();
707 int dmasz = GET_MAX_HW_ELTS()/3*3;
708 GLuint j, nr;
709 ELT_TYPE *dest;
710
711 if (start+2 >= count)
712 return;
713
714 ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
715
716
717 /* Emit whole number of tris in total. dmasz is already a multiple
718 * of 3.
719 */
720 count -= (count-start)%3;
721
722 for (j = start; j < count; j += nr) {
723 nr = MIN2( dmasz, count - j );
724 dest = ALLOC_ELTS( nr );
725 dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
726 CLOSE_ELTS();
727 }
728 }
729
730
731
732 static void TAG(render_tri_strip_elts)( GLcontext *ctx,
733 GLuint start,
734 GLuint count,
735 GLuint flags )
736 {
737 LOCAL_VARS;
738 GLuint j, nr;
739 GLuint *elts = GET_MESA_ELTS();
740 int dmasz = GET_MAX_HW_ELTS();
741 ELT_TYPE *dest;
742
743 if (start+2 >= count)
744 return;
745
746 ELT_INIT( GL_TRIANGLE_STRIP, HW_TRIANGLE_STRIP_0 );
747
748 /* Keep the same winding over multiple buffers:
749 */
750 dmasz -= (dmasz & 1);
751
752 for (j = start ; j + 2 < count; j += nr - 2 ) {
753 nr = MIN2( dmasz, count - j );
754
755 dest = ALLOC_ELTS( nr );
756 dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
757 CLOSE_ELTS();
758 }
759 }
760
761 static void TAG(render_tri_fan_elts)( GLcontext *ctx,
762 GLuint start,
763 GLuint count,
764 GLuint flags )
765 {
766 LOCAL_VARS;
767 GLuint *elts = GET_MESA_ELTS();
768 GLuint j, nr;
769 int dmasz = GET_MAX_HW_ELTS();
770 ELT_TYPE *dest;
771
772 if (start+2 >= count)
773 return;
774
775 ELT_INIT( GL_TRIANGLE_FAN, HW_TRIANGLE_FAN );
776
777 for (j = start + 1 ; j + 1 < count; j += nr - 1 ) {
778 nr = MIN2( dmasz, count - j + 1 );
779 dest = ALLOC_ELTS( nr );
780 dest = TAG(emit_elts)( ctx, dest, elts+start, 1 );
781 dest = TAG(emit_elts)( ctx, dest, elts+j, nr - 1 );
782 CLOSE_ELTS();
783 }
784 }
785
786
787 static void TAG(render_poly_elts)( GLcontext *ctx,
788 GLuint start,
789 GLuint count,
790 GLuint flags )
791 {
792 LOCAL_VARS;
793 GLuint *elts = GET_MESA_ELTS();
794 GLuint j, nr;
795 int dmasz = GET_MAX_HW_ELTS();
796 ELT_TYPE *dest;
797
798 if (start+2 >= count)
799 return;
800
801 ELT_INIT( GL_POLYGON, HW_POLYGON );
802
803 for (j = start + 1 ; j + 1 < count ; j += nr - 1 ) {
804 nr = MIN2( dmasz, count - j + 1 );
805 dest = ALLOC_ELTS( nr );
806 dest = TAG(emit_elts)( ctx, dest, elts+start, 1 );
807 dest = TAG(emit_elts)( ctx, dest, elts+j, nr - 1 );
808 CLOSE_ELTS();
809 }
810 }
811
812 static void TAG(render_quad_strip_elts)( GLcontext *ctx,
813 GLuint start,
814 GLuint count,
815 GLuint flags )
816 {
817 if (start+3 >= count)
818 return;
819
820 if (HAVE_QUAD_STRIPS && 0) {
821 }
822 else {
823 LOCAL_VARS;
824 GLuint *elts = GET_MESA_ELTS();
825 int dmasz = GET_MAX_HW_ELTS();
826 GLuint j, nr;
827 ELT_TYPE *dest;
828
829 /* Emit whole number of quads in total, and in each buffer.
830 */
831 dmasz -= dmasz & 1;
832 count -= (count-start) & 1;
833
834 if (ctx->_TriangleCaps & DD_FLATSHADE) {
835 ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
836
837 dmasz = dmasz/6*2;
838
839 for (j = start; j + 3 < count; j += nr - 2 ) {
840 nr = MIN2( dmasz, count - j );
841
842 if (nr >= 4)
843 {
844 GLint quads = (nr/2)-1;
845 ELT_TYPE *dest = ALLOC_ELTS( quads*6 );
846 GLint i;
847
848 for ( i = j-start ; i < j-start+quads ; i++, elts += 2 ) {
849 EMIT_TWO_ELTS( dest, 0, elts[0], elts[1] );
850 EMIT_TWO_ELTS( dest, 2, elts[2], elts[1] );
851 EMIT_TWO_ELTS( dest, 4, elts[3], elts[2] );
852 dest += 6;
853 }
854
855 CLOSE_ELTS();
856 }
857 }
858 }
859 else {
860 ELT_INIT( GL_TRIANGLE_STRIP, HW_TRIANGLE_STRIP_0 );
861
862 for (j = start; j + 3 < count; j += nr - 2 ) {
863 nr = MIN2( dmasz, count - j );
864 dest = ALLOC_ELTS( nr );
865 dest = TAG(emit_elts)( ctx, dest, elts+j, nr );
866 CLOSE_ELTS();
867 }
868 }
869 }
870 }
871
872
873 static void TAG(render_quads_elts)( GLcontext *ctx,
874 GLuint start,
875 GLuint count,
876 GLuint flags )
877 {
878 if (start+3 >= count)
879 return;
880
881 if (HAVE_QUADS && 0) {
882 } else {
883 LOCAL_VARS;
884 GLuint *elts = GET_MESA_ELTS();
885 int dmasz = GET_MAX_HW_ELTS();
886 GLuint j, nr;
887
888 ELT_INIT( GL_TRIANGLES, HW_TRIANGLES );
889
890 /* Emit whole number of quads in total, and in each buffer.
891 */
892 dmasz -= dmasz & 3;
893 count -= (count-start) & 3;
894
895 /* Adjust for rendering as triangles:
896 */
897 dmasz = dmasz/6*4;
898
899 for (j = start; j + 3 < count; j += nr ) {
900 nr = MIN2( dmasz, count - j );
901
902 {
903 GLint quads = nr/4;
904 ELT_TYPE *dest = ALLOC_ELTS( quads * 6 );
905 GLint i;
906
907 for ( i = j-start ; i < j-start+quads ; i++, elts += 4 ) {
908 EMIT_TWO_ELTS( dest, 0, elts[0], elts[1] );
909 EMIT_TWO_ELTS( dest, 2, elts[3], elts[1] );
910 EMIT_TWO_ELTS( dest, 4, elts[2], elts[3] );
911 dest += 6;
912 }
913
914 CLOSE_ELTS();
915 }
916 }
917 }
918 }
919
920
921
922 static render_func TAG(render_tab_elts)[GL_POLYGON+2] =
923 {
924 TAG(render_points_elts),
925 TAG(render_lines_elts),
926 TAG(render_line_loop_elts),
927 TAG(render_line_strip_elts),
928 TAG(render_triangles_elts),
929 TAG(render_tri_strip_elts),
930 TAG(render_tri_fan_elts),
931 TAG(render_quads_elts),
932 TAG(render_quad_strip_elts),
933 TAG(render_poly_elts),
934 TAG(render_noop),
935 };