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