1 /*
2 * Permission is hereby granted, free of charge, to any person obtaining a
3 * copy of this software and associated documentation files (the "Software"),
4 * to deal in the Software without restriction, including without limitation
5 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
6 * and/or sell copies of the Software, and to permit persons to whom the
7 * Software is furnished to do so, subject to the following conditions:
8 *
9 * The above copyright notice and this permission notice (including the next
10 * paragraph) shall be included in all copies or substantial portions of the
11 * Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 * IN THE SOFTWARE.
20 */
21
22 #include "pipe/p_defines.h"
23 #include "util/u_debug.h"
24 #include "util/u_split_draw.h"
25
26 bool
u_split_draw(const struct pipe_draw_info * info,uint32_t max_verts,uint32_t * count,uint32_t * step)27 u_split_draw(const struct pipe_draw_info *info, uint32_t max_verts,
28 uint32_t *count, uint32_t *step)
29 {
30 if (*count <= max_verts) {
31 *step = *count;
32 return false;
33 }
34
35 switch (info->mode) {
36 case PIPE_PRIM_POINTS:
37 *count = *step = max_verts;
38 break;
39 case PIPE_PRIM_LINES:
40 *count = *step = max_verts - (max_verts % 2);
41 break;
42 case PIPE_PRIM_LINE_STRIP:
43 *count = max_verts;
44 *step = max_verts - 1;
45 break;
46 case PIPE_PRIM_LINE_LOOP:
47 *count = max_verts;
48 *step = max_verts - 1;
49 debug_warn_once("unhandled line loop "
50 "looping behavior with "
51 ">max vert count\n");
52 break;
53 case PIPE_PRIM_TRIANGLES:
54 *count = *step = max_verts - (max_verts % 3);
55 break;
56 case PIPE_PRIM_TRIANGLE_STRIP:
57 *count = max_verts;
58 *step = max_verts - 2;
59 break;
60 default:
61 debug_warn_once("unhandled primitive "
62 "max vert count, truncating\n");
63 *count = *step = max_verts;
64 }
65
66 return true;
67 }
68