1/**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * 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
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29  * Authors:
30  *   Keith Whitwell <keithw@vmware.com>
31  */
32
33#include "draw/draw_context.h"
34#include "draw/draw_private.h"
35#include "draw/draw_pt.h"
36#include "util/u_debug.h"
37
38
39void
40draw_pt_split_prim(enum pipe_prim_type prim, unsigned *first, unsigned *incr)
41{
42   switch (prim) {
43   case PIPE_PRIM_POINTS:
44      *first = 1;
45      *incr = 1;
46      break;
47   case PIPE_PRIM_LINES:
48      *first = 2;
49      *incr = 2;
50      break;
51   case PIPE_PRIM_LINE_STRIP:
52   case PIPE_PRIM_LINE_LOOP:
53      *first = 2;
54      *incr = 1;
55      break;
56   case PIPE_PRIM_LINES_ADJACENCY:
57      *first = 4;
58      *incr = 4;
59      break;
60   case PIPE_PRIM_LINE_STRIP_ADJACENCY:
61      *first = 4;
62      *incr = 1;
63      break;
64   case PIPE_PRIM_TRIANGLES:
65      *first = 3;
66      *incr = 3;
67      break;
68   case PIPE_PRIM_TRIANGLES_ADJACENCY:
69      *first = 6;
70      *incr = 6;
71      break;
72   case PIPE_PRIM_TRIANGLE_STRIP:
73   case PIPE_PRIM_TRIANGLE_FAN:
74   case PIPE_PRIM_POLYGON:
75      *first = 3;
76      *incr = 1;
77      break;
78   case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
79      *first = 6;
80      *incr = 2;
81      break;
82   case PIPE_PRIM_QUADS:
83      *first = 4;
84      *incr = 4;
85      break;
86   case PIPE_PRIM_QUAD_STRIP:
87      *first = 4;
88      *incr = 2;
89      break;
90   default:
91      assert(0);
92      *first = 0;
93      *incr = 1;		/* set to one so that count % incr works */
94      break;
95   }
96}
97
98
99unsigned
100draw_pt_trim_count(unsigned count, unsigned first, unsigned incr)
101{
102   if (count < first)
103      return 0;
104   return count - (count - first) % incr;
105}
106