Merge commit 'origin/gallium-master-merge'
[mesa.git] / src / gallium / auxiliary / draw / draw_pt.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 <keith@tungstengraphics.com>
31 */
32
33 #ifndef DRAW_PT_H
34 #define DRAW_PT_H
35
36 #include "pipe/p_compiler.h"
37
38 typedef unsigned (*pt_elt_func)( const void *elts, unsigned idx );
39
40 struct draw_pt_middle_end;
41 struct draw_context;
42
43
44 #define PT_SHADE 0x1
45 #define PT_CLIPTEST 0x2
46 #define PT_PIPELINE 0x4
47 #define PT_MAX_MIDDLE 0x8
48
49
50 /* The "front end" - prepare sets of fetch, draw elements for the
51 * middle end.
52 *
53 * Currenly one version of this:
54 * - vcache - catchall implementation, decomposes to TRI/LINE/POINT prims
55 * Later:
56 * - varray, varray_split
57 * - velement, velement_split
58 *
59 * Currenly only using the vcache version.
60 */
61 struct draw_pt_front_end {
62 void (*prepare)( struct draw_pt_front_end *,
63 unsigned prim,
64 struct draw_pt_middle_end *,
65 unsigned opt );
66
67 void (*run)( struct draw_pt_front_end *,
68 pt_elt_func elt_func,
69 const void *elt_ptr,
70 unsigned count );
71
72 void (*finish)( struct draw_pt_front_end * );
73 void (*destroy)( struct draw_pt_front_end * );
74 };
75
76
77 /* The "middle end" - prepares actual hardware vertices for the
78 * hardware backend.
79 *
80 * Currently two versions of this:
81 * - fetch, vertex shade, cliptest, prim-pipeline
82 * - fetch, emit (ie passthrough)
83 */
84 struct draw_pt_middle_end {
85 void (*prepare)( struct draw_pt_middle_end *,
86 unsigned prim,
87 unsigned opt,
88 unsigned *max_vertices );
89
90 void (*run)( struct draw_pt_middle_end *,
91 const unsigned *fetch_elts,
92 unsigned fetch_count,
93 const ushort *draw_elts,
94 unsigned draw_count );
95
96 void (*run_linear)(struct draw_pt_middle_end *,
97 unsigned start,
98 unsigned count);
99
100 /* Transform all vertices in a linear range and then draw them with
101 * the supplied element list. May fail and return FALSE.
102 */
103 boolean (*run_linear_elts)( struct draw_pt_middle_end *,
104 unsigned fetch_start,
105 unsigned fetch_count,
106 const ushort *draw_elts,
107 unsigned draw_count );
108
109 int (*get_max_vertex_count)( struct draw_pt_middle_end * );
110
111 void (*finish)( struct draw_pt_middle_end * );
112 void (*destroy)( struct draw_pt_middle_end * );
113 };
114
115
116 /* The "back end" - supplied by the driver, defined in draw_vbuf.h.
117 */
118 struct vbuf_render;
119 struct vertex_header;
120
121
122 /* Helper functions.
123 */
124 pt_elt_func draw_pt_elt_func( struct draw_context *draw );
125 const void *draw_pt_elt_ptr( struct draw_context *draw,
126 unsigned start );
127
128 /* Frontends:
129 *
130 * Currently only the general-purpose vcache implementation, could add
131 * a special case for tiny vertex buffers.
132 */
133 struct draw_pt_front_end *draw_pt_vcache( struct draw_context *draw );
134 struct draw_pt_front_end *draw_pt_varray(struct draw_context *draw);
135
136
137 /* Middle-ends:
138 *
139 * Currently one general-purpose case which can do all possibilities,
140 * at the slight expense of creating a vertex_header in some cases
141 * unecessarily.
142 *
143 * The special case fetch_emit code avoids pipeline vertices
144 * altogether and builds hardware vertices directly from API
145 * vertex_elements.
146 */
147 struct draw_pt_middle_end *draw_pt_fetch_emit( struct draw_context *draw );
148 struct draw_pt_middle_end *draw_pt_middle_fse( struct draw_context *draw );
149 struct draw_pt_middle_end *draw_pt_fetch_pipeline_or_emit(struct draw_context *draw);
150
151
152 /* More helpers:
153 */
154 boolean draw_pt_get_edgeflag( struct draw_context *draw,
155 unsigned idx );
156
157
158 /*******************************************************************************
159 * HW vertex emit:
160 */
161 struct pt_emit;
162
163 void draw_pt_emit_prepare( struct pt_emit *emit,
164 unsigned prim,
165 unsigned *max_vertices );
166
167 void draw_pt_emit( struct pt_emit *emit,
168 const float (*vertex_data)[4],
169 unsigned vertex_count,
170 unsigned stride,
171 const ushort *elts,
172 unsigned count );
173
174 void draw_pt_emit_linear( struct pt_emit *emit,
175 const float (*vertex_data)[4],
176 unsigned vertex_count,
177 unsigned stride,
178 unsigned start,
179 unsigned count );
180
181 void draw_pt_emit_destroy( struct pt_emit *emit );
182
183 struct pt_emit *draw_pt_emit_create( struct draw_context *draw );
184
185
186 /*******************************************************************************
187 * API vertex fetch:
188 */
189
190 struct pt_fetch;
191 void draw_pt_fetch_prepare( struct pt_fetch *fetch,
192 unsigned vertex_size );
193
194 void draw_pt_fetch_run( struct pt_fetch *fetch,
195 const unsigned *elts,
196 unsigned count,
197 char *verts );
198
199 void draw_pt_fetch_run_linear( struct pt_fetch *fetch,
200 unsigned start,
201 unsigned count,
202 char *verts );
203
204 void draw_pt_fetch_destroy( struct pt_fetch *fetch );
205
206 struct pt_fetch *draw_pt_fetch_create( struct draw_context *draw );
207
208 /*******************************************************************************
209 * Post-VS: cliptest, rhw, viewport
210 */
211 struct pt_post_vs;
212
213 boolean draw_pt_post_vs_run( struct pt_post_vs *pvs,
214 struct vertex_header *pipeline_verts,
215 unsigned stride,
216 unsigned count );
217
218 void draw_pt_post_vs_prepare( struct pt_post_vs *pvs,
219 boolean bypass_clipping,
220 boolean identity_viewport,
221 boolean opengl );
222
223 struct pt_post_vs *draw_pt_post_vs_create( struct draw_context *draw );
224
225 void draw_pt_post_vs_destroy( struct pt_post_vs *pvs );
226
227
228 /*******************************************************************************
229 * Utils:
230 */
231 void draw_pt_split_prim(unsigned prim, unsigned *first, unsigned *incr);
232 unsigned draw_pt_reduced_prim(unsigned prim);
233
234
235 #endif