2 * Mesa 3-D graphics library
5 * Copyright 2007-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 #define CONCAT2(name, elt_type) name ## elt_type
28 #define CONCAT(name, elt_type) CONCAT2(name, elt_type)
33 * Fetch all elements in [min_index, max_index] with bias, and use the
34 * (rebased) index buffer as the draw elements.
37 CONCAT(vsplit_primitive_, ELT_TYPE)(struct vsplit_frontend *vsplit,
38 unsigned istart, unsigned icount)
40 struct draw_context *draw = vsplit->draw;
41 const ELT_TYPE *ib = (const ELT_TYPE *)
42 ((const char *) draw->pt.user.elts + draw->pt.index_buffer.offset);
43 const unsigned min_index = draw->pt.user.min_index;
44 const unsigned max_index = draw->pt.user.max_index;
45 const int elt_bias = draw->pt.user.eltBias;
46 unsigned fetch_start, fetch_count;
47 const ushort *draw_elts = NULL;
52 /* use the ib directly */
53 if (min_index == 0 && sizeof(ib[0]) == sizeof(draw_elts[0])) {
54 if (icount > vsplit->max_vertices)
57 for (i = 0; i < icount; i++) {
59 if (idx < min_index || idx > max_index) {
60 debug_printf("warning: index out of range\n");
63 draw_elts = (const ushort *) ib;
66 /* have to go through vsplit->draw_elts */
67 if (icount > vsplit->segment_size)
71 /* this is faster only when we fetch less elements than the normal path */
72 if (max_index - min_index > icount - 1)
75 if (elt_bias < 0 && min_index < -elt_bias)
79 for (i = 0; i < draw->pt.nr_vertex_elements; i++) {
80 if (draw->pt.vertex_element[i].instance_divisor)
84 fetch_start = min_index + elt_bias;
85 fetch_count = max_index - min_index + 1;
89 for (i = 0; i < icount; i++) {
92 if (idx < min_index || idx > max_index) {
93 debug_printf("warning: index out of range\n");
95 vsplit->draw_elts[i] = (ushort) idx;
99 for (i = 0; i < icount; i++) {
100 ELT_TYPE idx = ib[i];
102 if (idx < min_index || idx > max_index) {
103 debug_printf("warning: index out of range\n");
105 vsplit->draw_elts[i] = (ushort) (idx - min_index);
109 draw_elts = vsplit->draw_elts;
112 return vsplit->middle->run_linear_elts(vsplit->middle,
113 fetch_start, fetch_count,
114 draw_elts, icount, 0x0);
118 * Use the cache to prepare the fetch and draw elements, and flush.
120 * When spoken is TRUE, ispoken replaces istart; When close is TRUE, iclose is
124 CONCAT(vsplit_segment_cache_, ELT_TYPE)(struct vsplit_frontend *vsplit,
126 unsigned istart, unsigned icount,
127 boolean spoken, unsigned ispoken,
128 boolean close, unsigned iclose)
130 struct draw_context *draw = vsplit->draw;
131 const ELT_TYPE *ib = (const ELT_TYPE *)
132 ((const char *) draw->pt.user.elts + draw->pt.index_buffer.offset);
133 const int ibias = draw->pt.user.eltBias;
136 assert(icount + !!close <= vsplit->segment_size);
138 vsplit_clear_cache(vsplit);
143 ADD_CACHE(vsplit, ib[ispoken]);
145 for (i = spoken; i < icount; i++)
146 ADD_CACHE(vsplit, ib[istart + i]);
149 ADD_CACHE(vsplit, ib[iclose]);
151 else if (ibias > 0) {
153 ADD_CACHE(vsplit, (uint) ib[ispoken] + ibias);
155 for (i = spoken; i < icount; i++)
156 ADD_CACHE(vsplit, (uint) ib[istart + i] + ibias);
159 ADD_CACHE(vsplit, (uint) ib[iclose] + ibias);
163 if (ib[ispoken] < -ibias)
165 ADD_CACHE(vsplit, ib[ispoken] + ibias);
168 for (i = spoken; i < icount; i++) {
169 if (ib[istart + i] < -ibias)
171 ADD_CACHE(vsplit, ib[istart + i] + ibias);
175 if (ib[iclose] < -ibias)
177 ADD_CACHE(vsplit, ib[iclose] + ibias);
181 vsplit_flush_cache(vsplit, flags);
185 CONCAT(vsplit_segment_simple_, ELT_TYPE)(struct vsplit_frontend *vsplit,
190 CONCAT(vsplit_segment_cache_, ELT_TYPE)(vsplit,
191 flags, istart, icount, FALSE, 0, FALSE, 0);
195 CONCAT(vsplit_segment_loop_, ELT_TYPE)(struct vsplit_frontend *vsplit,
201 const boolean close_loop = ((flags) == DRAW_SPLIT_BEFORE);
203 CONCAT(vsplit_segment_cache_, ELT_TYPE)(vsplit,
204 flags, istart, icount, FALSE, 0, close_loop, i0);
208 CONCAT(vsplit_segment_fan_, ELT_TYPE)(struct vsplit_frontend *vsplit,
214 const boolean use_spoken = (((flags) & DRAW_SPLIT_BEFORE) != 0);
216 CONCAT(vsplit_segment_cache_, ELT_TYPE)(vsplit,
217 flags, istart, icount, use_spoken, i0, FALSE, 0);
221 struct vsplit_frontend *vsplit = (struct vsplit_frontend *) frontend; \
222 const unsigned prim = vsplit->prim; \
223 const unsigned max_count_simple = vsplit->segment_size; \
224 const unsigned max_count_loop = vsplit->segment_size - 1; \
225 const unsigned max_count_fan = vsplit->segment_size;
227 #define PRIMITIVE(istart, icount) \
228 CONCAT(vsplit_primitive_, ELT_TYPE)(vsplit, istart, icount)
233 vsplit_segment_simple_linear(struct vsplit_frontend *vsplit, unsigned flags,
234 unsigned istart, unsigned icount)
236 assert(icount <= vsplit->max_vertices);
237 vsplit->middle->run_linear(vsplit->middle, istart, icount, flags);
241 vsplit_segment_loop_linear(struct vsplit_frontend *vsplit, unsigned flags,
242 unsigned istart, unsigned icount, unsigned i0)
244 boolean close_loop = (flags == DRAW_SPLIT_BEFORE);
247 assert(icount + !!close_loop <= vsplit->segment_size);
250 for (nr = 0; nr < icount; nr++)
251 vsplit->fetch_elts[nr] = istart + nr;
252 vsplit->fetch_elts[nr++] = i0;
254 vsplit->middle->run(vsplit->middle, vsplit->fetch_elts, nr,
255 vsplit->identity_draw_elts, nr, flags);
258 vsplit->middle->run_linear(vsplit->middle, istart, icount, flags);
263 vsplit_segment_fan_linear(struct vsplit_frontend *vsplit, unsigned flags,
264 unsigned istart, unsigned icount, unsigned i0)
266 boolean use_spoken = ((flags & DRAW_SPLIT_BEFORE) != 0);
269 assert(icount <= vsplit->segment_size);
272 /* replace istart by i0 */
273 vsplit->fetch_elts[nr++] = i0;
274 for (i = 1 ; i < icount; i++)
275 vsplit->fetch_elts[nr++] = istart + i;
277 vsplit->middle->run(vsplit->middle, vsplit->fetch_elts, nr,
278 vsplit->identity_draw_elts, nr, flags);
281 vsplit->middle->run_linear(vsplit->middle, istart, icount, flags);
286 struct vsplit_frontend *vsplit = (struct vsplit_frontend *) frontend; \
287 const unsigned prim = vsplit->prim; \
288 const unsigned max_count_simple = vsplit->max_vertices; \
289 const unsigned max_count_loop = vsplit->segment_size - 1; \
290 const unsigned max_count_fan = vsplit->segment_size;
292 #define PRIMITIVE(istart, icount) FALSE
294 #define ELT_TYPE linear
296 #endif /* ELT_TYPE */
299 struct draw_pt_front_end *frontend, \
303 #define SEGMENT_SIMPLE(flags, istart, icount) \
304 CONCAT(vsplit_segment_simple_, ELT_TYPE)(vsplit, flags, istart, icount)
306 #define SEGMENT_LOOP(flags, istart, icount, i0) \
307 CONCAT(vsplit_segment_loop_, ELT_TYPE)(vsplit, flags, istart, icount, i0)
309 #define SEGMENT_FAN(flags, istart, icount, i0) \
310 CONCAT(vsplit_segment_fan_, ELT_TYPE)(vsplit, flags, istart, icount, i0)
312 #include "draw_split_tmp.h"