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