revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / workbench / libs / mesa / src / gallium / auxiliary / draw / draw_split_tmp.h
blob47defc62b96a8ade23be458d69bf1edfeddb1658
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.9
5 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Copyright (C) 2010 LunarG Inc.
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:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
27 static void
28 FUNC(FUNC_VARS)
30 unsigned first, incr;
31 LOCAL_VARS
34 * prim, start, count, and max_count_{simple,loop,fan} should have been
35 * defined
37 if (0) {
38 debug_printf("%s: prim 0x%x, start %d, count %d, max_count_simple %d, "
39 "max_count_loop %d, max_count_fan %d\n",
40 __FUNCTION__, prim, start, count, max_count_simple,
41 max_count_loop, max_count_fan);
44 draw_pt_split_prim(prim, &first, &incr);
45 /* sanitize primitive length */
46 count = draw_pt_trim_count(count, first, incr);
47 if (count < first)
48 return;
50 /* try flushing the entire primitive */
51 if (PRIMITIVE(start, count))
52 return;
54 /* must be able to at least flush two complete primitives */
55 assert(max_count_simple >= first + incr &&
56 max_count_loop >= first + incr &&
57 max_count_fan >= first + incr);
59 /* no splitting required */
60 if (count <= max_count_simple) {
61 SEGMENT_SIMPLE(0x0, start, count);
63 else {
64 const unsigned rollback = first - incr;
65 unsigned flags = DRAW_SPLIT_AFTER, seg_start = 0, seg_max;
68 * Both count and seg_max below are explicitly trimmed. Because
70 * seg_start = N * (seg_max - rollback) = N' * incr,
72 * we have
74 * remaining = count - seg_start = first + N'' * incr.
76 * That is, remaining is implicitly trimmed.
78 switch (prim) {
79 case PIPE_PRIM_POINTS:
80 case PIPE_PRIM_LINES:
81 case PIPE_PRIM_LINE_STRIP:
82 case PIPE_PRIM_TRIANGLES:
83 case PIPE_PRIM_TRIANGLE_STRIP:
84 case PIPE_PRIM_QUADS:
85 case PIPE_PRIM_QUAD_STRIP:
86 case PIPE_PRIM_LINES_ADJACENCY:
87 case PIPE_PRIM_LINE_STRIP_ADJACENCY:
88 case PIPE_PRIM_TRIANGLES_ADJACENCY:
89 case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
90 seg_max =
91 draw_pt_trim_count(MIN2(max_count_simple, count), first, incr);
92 if (prim == PIPE_PRIM_TRIANGLE_STRIP ||
93 prim == PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY) {
94 /* make sure we flush even number of triangles at a time */
95 if (seg_max < count && !(((seg_max - first) / incr) & 1))
96 seg_max -= incr;
99 do {
100 const unsigned remaining = count - seg_start;
102 if (remaining > seg_max) {
103 SEGMENT_SIMPLE(flags, start + seg_start, seg_max);
104 seg_start += seg_max - rollback;
106 flags |= DRAW_SPLIT_BEFORE;
108 else {
109 flags &= ~DRAW_SPLIT_AFTER;
111 SEGMENT_SIMPLE(flags, start + seg_start, remaining);
112 seg_start += remaining;
114 } while (seg_start < count);
115 break;
117 case PIPE_PRIM_LINE_LOOP:
118 seg_max =
119 draw_pt_trim_count(MIN2(max_count_loop, count), first, incr);
121 do {
122 const unsigned remaining = count - seg_start;
124 if (remaining > seg_max) {
125 SEGMENT_LOOP(flags, start + seg_start, seg_max, start);
126 seg_start += seg_max - rollback;
128 flags |= DRAW_SPLIT_BEFORE;
130 else {
131 flags &= ~DRAW_SPLIT_AFTER;
133 SEGMENT_LOOP(flags, start + seg_start, remaining, start);
134 seg_start += remaining;
136 } while (seg_start < count);
137 break;
139 case PIPE_PRIM_TRIANGLE_FAN:
140 case PIPE_PRIM_POLYGON:
141 seg_max =
142 draw_pt_trim_count(MIN2(max_count_fan, count), first, incr);
144 do {
145 const unsigned remaining = count - seg_start;
147 if (remaining > seg_max) {
148 SEGMENT_FAN(flags, start + seg_start, seg_max, start);
149 seg_start += seg_max - rollback;
151 flags |= DRAW_SPLIT_BEFORE;
153 else {
154 flags &= ~DRAW_SPLIT_AFTER;
156 SEGMENT_FAN(flags, start + seg_start, remaining, start);
157 seg_start += remaining;
159 } while (seg_start < count);
160 break;
162 default:
163 assert(0);
164 break;
169 #undef FUNC
170 #undef FUNC_VARS
171 #undef LOCAL_VARS
173 #undef PRIMITIVE
174 #undef SEGMENT_SIMPLE
175 #undef SEGMENT_LOOP
176 #undef SEGMENT_FAN