draw: use common exit path in pipeline finish.
[mesa.git] / src / gallium / auxiliary / indices / u_indices.h
1 /*
2 * Copyright 2009 VMware, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #ifndef U_INDICES_H
26 #define U_INDICES_H
27
28 #include "pipe/p_compiler.h"
29 #include "pipe/p_defines.h"
30
31 /* First/last provoking vertex */
32 #define PV_FIRST 0
33 #define PV_LAST 1
34 #define PV_COUNT 2
35
36 /* primitive restart disable/enable flags */
37 #define PR_DISABLE 0
38 #define PR_ENABLE 1
39 #define PR_COUNT 2
40
41
42 /**
43 * Index translator function (for glDrawElements() case)
44 *
45 * \param in the input index buffer
46 * \param start the index of the first vertex (pipe_draw_info::start)
47 * \param nr the number of vertices (pipe_draw_info::count)
48 * \param out output buffer big enough for nr vertices (of
49 * @out_index_size bytes each)
50 */
51 typedef void (*u_translate_func)( const void *in,
52 unsigned start,
53 unsigned in_nr,
54 unsigned out_nr,
55 unsigned restart_index,
56 void *out );
57
58 /**
59 * Index generator function (for glDrawArrays() case)
60 *
61 * \param start the index of the first vertex (pipe_draw_info::start)
62 * \param nr the number of vertices (pipe_draw_info::count)
63 * \param out output buffer big enough for nr vertices (of
64 * @out_index_size bytes each)
65 */
66 typedef void (*u_generate_func)( unsigned start,
67 unsigned nr,
68 void *out );
69
70
71 /* Return codes describe the translate/generate operation. Caller may
72 * be able to reuse translated indices under some circumstances.
73 */
74 enum indices_mode {
75 U_TRANSLATE_ERROR = -1,
76 U_TRANSLATE_NORMAL = 1,
77 U_TRANSLATE_MEMCPY = 2,
78 U_GENERATE_LINEAR = 3,
79 U_GENERATE_REUSABLE= 4,
80 U_GENERATE_ONE_OFF = 5,
81 };
82
83 void u_index_init( void );
84
85
86 /**
87 * For indexed drawing, this function determines what kind of primitive
88 * transformation is needed (if any) for handling:
89 * - unsupported primitive types (such as PIPE_PRIM_POLYGON)
90 * - changing the provoking vertex
91 * - primitive restart
92 * - index size (1 byte, 2 byte or 4 byte indexes)
93 */
94 enum indices_mode
95 u_index_translator(unsigned hw_mask,
96 enum pipe_prim_type prim,
97 unsigned in_index_size,
98 unsigned nr,
99 unsigned in_pv, /* API */
100 unsigned out_pv, /* hardware */
101 unsigned prim_restart,
102 enum pipe_prim_type *out_prim,
103 unsigned *out_index_size,
104 unsigned *out_nr,
105 u_translate_func *out_translate);
106
107
108 /**
109 * For non-indexed drawing, this function determines what kind of primitive
110 * transformation is needed (see above).
111 *
112 * Note that even when generating it is necessary to know what the
113 * API's PV is, as the indices generated will depend on whether it is
114 * the same as hardware or not, and in the case of triangle strips,
115 * whether it is first or last.
116 */
117 enum indices_mode
118 u_index_generator(unsigned hw_mask,
119 enum pipe_prim_type prim,
120 unsigned start,
121 unsigned nr,
122 unsigned in_pv, /* API */
123 unsigned out_pv, /* hardware */
124 enum pipe_prim_type *out_prim,
125 unsigned *out_index_size,
126 unsigned *out_nr,
127 u_generate_func *out_generate);
128
129
130 void u_unfilled_init( void );
131
132 /**
133 * If the driver can't handle "unfilled" primitives (i.e. drawing triangle
134 * primitives as 3 lines or 3 points) this function can be used to translate
135 * an indexed primitive into a new indexed primitive to draw as lines or
136 * points.
137 */
138 enum indices_mode
139 u_unfilled_translator(enum pipe_prim_type prim,
140 unsigned in_index_size,
141 unsigned nr,
142 unsigned unfilled_mode,
143 enum pipe_prim_type *out_prim,
144 unsigned *out_index_size,
145 unsigned *out_nr,
146 u_translate_func *out_translate);
147
148 /**
149 * As above, but for non-indexed (array) primitives.
150 */
151 enum indices_mode
152 u_unfilled_generator(enum pipe_prim_type prim,
153 unsigned start,
154 unsigned nr,
155 unsigned unfilled_mode,
156 enum pipe_prim_type *out_prim,
157 unsigned *out_index_size,
158 unsigned *out_nr,
159 u_generate_func *out_generate);
160
161 #endif