fd0d158fcf7cb43dc44bb83559bd899652059ec8
[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 /* We use the top couple of bits in the vertex fetch index to convey a
44 * little API information. This limits the number of vertices we can
45 * address to only 1 billion -- if that becomes a problem, these could
46 * be moved out & passed separately.
47 */
48 #define DRAW_PT_EDGEFLAG (1<<30)
49 #define DRAW_PT_RESET_STIPPLE (1<<31)
50 #define DRAW_PT_FLAG_MASK (3<<30)
51
52
53 #define PT_SHADE 0x1
54 #define PT_CLIPTEST 0x2
55 #define PT_PIPELINE 0x4
56 #define PT_MAX_MIDDLE 0x8
57
58
59 /* The "front end" - prepare sets of fetch, draw elements for the
60 * middle end.
61 *
62 * Currenly one version of this:
63 * - vcache - catchall implementation, decomposes to TRI/LINE/POINT prims
64 * Later:
65 * - varray, varray_split
66 * - velement, velement_split
67 *
68 * Currenly only using the vcache version.
69 */
70 struct draw_pt_front_end {
71 void (*prepare)( struct draw_pt_front_end *,
72 unsigned prim,
73 struct draw_pt_middle_end *,
74 unsigned opt );
75
76 void (*run)( struct draw_pt_front_end *,
77 pt_elt_func elt_func,
78 const void *elt_ptr,
79 unsigned count );
80
81 void (*finish)( struct draw_pt_front_end * );
82 void (*destroy)( struct draw_pt_front_end * );
83 };
84
85
86 /* The "middle end" - prepares actual hardware vertices for the
87 * hardware backend.
88 *
89 * Currently two versions of this:
90 * - fetch, vertex shade, cliptest, prim-pipeline
91 * - fetch, emit (ie passthrough)
92 */
93 struct draw_pt_middle_end {
94 void (*prepare)( struct draw_pt_middle_end *,
95 unsigned prim,
96 unsigned opt );
97
98 void (*run)( struct draw_pt_middle_end *,
99 const unsigned *fetch_elts,
100 unsigned fetch_count,
101 const ushort *draw_elts,
102 unsigned draw_count );
103
104 void (*finish)( struct draw_pt_middle_end * );
105 void (*destroy)( struct draw_pt_middle_end * );
106 };
107
108
109 /* The "back end" - supplied by the driver, defined in draw_vbuf.h.
110 */
111 struct vbuf_render;
112 struct vertex_header;
113
114
115 /* Helper functions.
116 */
117 pt_elt_func draw_pt_elt_func( struct draw_context *draw );
118 const void *draw_pt_elt_ptr( struct draw_context *draw,
119 unsigned start );
120
121 /* Frontends:
122 *
123 * Currently only the general-purpose vcache implementation, could add
124 * a special case for tiny vertex buffers.
125 */
126 struct draw_pt_front_end *draw_pt_vcache( struct draw_context *draw );
127
128 /* Middle-ends:
129 *
130 * Currently one general-purpose case which can do all possibilities,
131 * at the slight expense of creating a vertex_header in some cases
132 * unecessarily.
133 *
134 * The special case fetch_emit code avoids pipeline vertices
135 * altogether and builds hardware vertices directly from API
136 * vertex_elements.
137 */
138 struct draw_pt_middle_end *draw_pt_fetch_emit( struct draw_context *draw );
139 struct draw_pt_middle_end *draw_pt_fetch_pipeline_or_emit(struct draw_context *draw);
140
141
142 /* More helpers:
143 */
144 boolean draw_pt_get_edgeflag( struct draw_context *draw,
145 unsigned idx );
146
147
148 /*******************************************************************************
149 * HW vertex emit:
150 */
151 struct pt_emit;
152
153 void draw_pt_emit_prepare( struct pt_emit *emit,
154 unsigned prim );
155
156 void draw_pt_emit( struct pt_emit *emit,
157 const float (*vertex_data)[4],
158 unsigned vertex_count,
159 unsigned stride,
160 const ushort *elts,
161 unsigned count );
162
163 void draw_pt_emit_destroy( struct pt_emit *emit );
164
165 struct pt_emit *draw_pt_emit_create( struct draw_context *draw );
166
167
168 /*******************************************************************************
169 * API vertex fetch:
170 */
171
172 struct pt_fetch;
173 void draw_pt_fetch_prepare( struct pt_fetch *fetch,
174 unsigned vertex_size );
175
176 void draw_pt_fetch_run( struct pt_fetch *fetch,
177 const unsigned *elts,
178 unsigned count,
179 char *verts );
180
181 void draw_pt_fetch_destroy( struct pt_fetch *fetch );
182
183 struct pt_fetch *draw_pt_fetch_create( struct draw_context *draw );
184
185 /*******************************************************************************
186 * Post-VS: cliptest, rhw, viewport
187 */
188 struct pt_post_vs;
189
190 boolean draw_pt_post_vs_run( struct pt_post_vs *pvs,
191 struct vertex_header *pipeline_verts,
192 unsigned stride,
193 unsigned count );
194
195 void draw_pt_post_vs_prepare( struct pt_post_vs *pvs,
196 boolean bypass_clipping,
197 boolean identity_viewport,
198 boolean opengl );
199
200 struct pt_post_vs *draw_pt_post_vs_create( struct draw_context *draw );
201
202 void draw_pt_post_vs_destroy( struct pt_post_vs *pvs );
203
204
205 #endif