Merge branch 'softpipe_0_1_branch' of git+ssh://brianp@git.freedesktop.org/git/mesa...
[mesa.git] / src / mesa / pipe / draw / draw_private.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 * Private data structures, etc for the draw module.
30 */
31
32
33 /**
34 * Authors:
35 * Keith Whitwell <keith@tungstengraphics.com>
36 * Brian Paul
37 */
38
39
40 #ifndef DRAW_PRIVATE_H
41 #define DRAW_PRIVATE_H
42
43
44 #include "main/glheader.h"
45 #include "pipe/p_state.h"
46 #include "pipe/p_defines.h"
47 #include "vf/vf.h"
48
49
50 /**
51 * Basic vertex info.
52 * Carry some useful information around with the vertices in the prim pipe.
53 */
54 struct vertex_header {
55 GLuint clipmask:12;
56 GLuint edgeflag:1;
57 GLuint pad:19;
58
59 GLfloat clip[4];
60
61 GLfloat data[][4]; /* Note variable size */
62 };
63
64 #define MAX_VERTEX_SIZE ((2 + FRAG_ATTRIB_MAX) * 4 * sizeof(GLfloat))
65
66
67
68 /**
69 * Basic info for a point/line/triangle primitive.
70 */
71 struct prim_header {
72 GLfloat det; /**< front/back face determinant */
73 GLuint reset_line_stipple:1;
74 GLuint edgeflags:3;
75 GLuint pad:28;
76 struct vertex_header *v[3]; /**< 1 to 3 vertex pointers */
77 };
78
79
80
81 struct draw_context;
82
83 /**
84 * Base class for all primitive drawing stages.
85 */
86 struct draw_stage
87 {
88 struct draw_context *draw; /**< parent context */
89
90 struct draw_stage *next; /**< next stage in pipeline */
91
92 struct vertex_header **tmp;
93 GLuint nr_tmps;
94
95 void (*begin)( struct draw_stage * );
96
97 void (*point)( struct draw_stage *,
98 struct prim_header * );
99
100 void (*line)( struct draw_stage *,
101 struct prim_header * );
102
103 void (*tri)( struct draw_stage *,
104 struct prim_header * );
105
106 void (*end)( struct draw_stage * );
107
108 void (*reset_stipple_counter)( struct draw_stage * );
109 };
110
111
112 #define PRIM_QUEUE_LENGTH 16
113 #define VCACHE_SIZE 32
114 #define VCACHE_OVERFLOW 4
115 #define VS_QUEUE_LENGTH (VCACHE_SIZE + VCACHE_OVERFLOW + 1) /* can never fill up */
116
117
118 /**
119 * Private context for the drawing module.
120 */
121 struct draw_context
122 {
123 struct {
124 struct draw_stage *first; /**< one of the following */
125
126 /* stages (in logical order) */
127 struct draw_stage *flatshade;
128 struct draw_stage *clip;
129 struct draw_stage *cull;
130 struct draw_stage *twoside;
131 struct draw_stage *offset;
132 struct draw_stage *unfilled;
133 struct draw_stage *setup; /* aka render/rasterize */
134 } pipeline;
135
136 /* pipe state that we need: */
137 struct pipe_setup_state setup;
138 struct pipe_viewport_state viewport;
139
140 /* Clip derived state:
141 */
142 GLfloat plane[12][4];
143 GLuint nr_planes;
144
145 GLuint vf_attr_to_slot[PIPE_ATTRIB_MAX];
146
147 struct vf_attr_map attrs[VF_ATTRIB_MAX];
148 GLuint nr_attrs;
149 GLuint vertex_size; /**< in bytes */
150 struct vertex_fetch *vf;
151
152 GLubyte *verts;
153 GLuint nr_vertices;
154 GLboolean in_vb;
155
156 void *elts;
157
158 struct vertex_header *(*get_vertex)( struct draw_context *draw,
159 GLuint i );
160
161 /* Post-tnl vertex cache:
162 */
163 struct {
164 GLuint referenced;
165 GLuint idx[VCACHE_SIZE + VCACHE_OVERFLOW];
166 struct vertex_header *vertex[VCACHE_SIZE + VCACHE_OVERFLOW];
167 GLuint overflow;
168 } vcache;
169
170 /* Vertex shader queue:
171 */
172 struct {
173 struct {
174 GLuint elt;
175 struct vertex_header *dest;
176 } queue[VS_QUEUE_LENGTH];
177 GLuint queue_nr;
178 } vs;
179
180 /* Prim pipeline queue:
181 */
182 struct {
183
184 /* Need to queue up primitives until their vertices have been
185 * transformed by a vs queue flush.
186 */
187 struct prim_header queue[PRIM_QUEUE_LENGTH];
188 GLuint queue_nr;
189 } pq;
190
191
192
193 GLenum prim; /**< GL_POINTS, GL_LINE_STRIP, GL_QUADS, etc */
194 unsigned reduced_prim;
195
196 /* Helper for tnl:
197 */
198 GLvector4f header;
199 };
200
201
202
203 extern struct draw_stage *draw_unfilled_stage( struct draw_context *context );
204 extern struct draw_stage *draw_twoside_stage( struct draw_context *context );
205 extern struct draw_stage *draw_offset_stage( struct draw_context *context );
206 extern struct draw_stage *draw_clip_stage( struct draw_context *context );
207 extern struct draw_stage *draw_flatshade_stage( struct draw_context *context );
208 extern struct draw_stage *draw_cull_stage( struct draw_context *context );
209
210
211 extern void draw_free_tmps( struct draw_stage *stage );
212 extern void draw_alloc_tmps( struct draw_stage *stage, GLuint nr );
213
214
215
216 /**
217 * Get a writeable copy of a vertex.
218 * \param stage drawing stage info
219 * \param vert the vertex to copy (source)
220 * \param idx index into stage's tmp[] array to put the copy (dest)
221 * \return pointer to the copied vertex
222 */
223 static INLINE struct vertex_header *
224 dup_vert( struct draw_stage *stage,
225 const struct vertex_header *vert,
226 GLuint idx )
227 {
228 struct vertex_header *tmp = stage->tmp[idx];
229 memcpy(tmp, vert, stage->draw->vertex_size );
230 return tmp;
231 }
232
233
234 #endif /* DRAW_PRIVATE_H */