Remove CVS keywords.
[mesa.git] / src / mesa / drivers / dri / tdfx / tdfx_vb.c
1 /*
2 * GLX Hardware Device Driver for Intel i810
3 * Copyright (C) 1999 Keith Whitwell
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
21 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 *
24 */
25
26 #include "main/glheader.h"
27 #include "main/mtypes.h"
28 #include "main/imports.h"
29 #include "main/macros.h"
30 #include "main/colormac.h"
31
32 #include "math/m_translate.h"
33 #include "swrast_setup/swrast_setup.h"
34
35 #include "tdfx_context.h"
36 #include "tdfx_vb.h"
37 #include "tdfx_tris.h"
38 #include "tdfx_state.h"
39 #include "tdfx_render.h"
40
41 static void copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc )
42 {
43 tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx );
44 tdfxVertex *dst = fxMesa->verts + edst;
45 tdfxVertex *src = fxMesa->verts + esrc;
46 *(GLuint *)&dst->color = *(GLuint *)&src->color;
47 }
48
49 static struct {
50 void (*emit)( GLcontext *, GLuint, GLuint, void * );
51 tnl_interp_func interp;
52 tnl_copy_pv_func copy_pv;
53 GLboolean (*check_tex_sizes)( GLcontext *ctx );
54 GLuint vertex_format;
55 } setup_tab[TDFX_MAX_SETUP];
56
57
58
59
60 #define GET_COLOR(ptr, idx) ((ptr)->data[idx])
61
62
63 static void interp_extras( GLcontext *ctx,
64 GLfloat t,
65 GLuint dst, GLuint out, GLuint in,
66 GLboolean force_boundary )
67 {
68 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
69
70 /*fprintf(stderr, "%s\n", __FUNCTION__);*/
71
72 if (VB->ColorPtr[1]) {
73 INTERP_4F( t,
74 GET_COLOR(VB->ColorPtr[1], dst),
75 GET_COLOR(VB->ColorPtr[1], out),
76 GET_COLOR(VB->ColorPtr[1], in) );
77 }
78
79 if (VB->EdgeFlag) {
80 VB->EdgeFlag[dst] = VB->EdgeFlag[out] || force_boundary;
81 }
82
83 setup_tab[TDFX_CONTEXT(ctx)->SetupIndex].interp(ctx, t, dst, out, in,
84 force_boundary);
85 }
86
87 static void copy_pv_extras( GLcontext *ctx, GLuint dst, GLuint src )
88 {
89 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
90
91 if (VB->ColorPtr[1]) {
92 COPY_4FV( GET_COLOR(VB->ColorPtr[1], dst),
93 GET_COLOR(VB->ColorPtr[1], src) );
94 }
95
96 setup_tab[TDFX_CONTEXT(ctx)->SetupIndex].copy_pv(ctx, dst, src);
97 }
98
99
100
101 #define IND (TDFX_XYZ_BIT|TDFX_RGBA_BIT)
102 #define TAG(x) x##_wg
103 #include "tdfx_vbtmp.h"
104
105 /* Special for tdfx: fog requires w
106 */
107 #define IND (TDFX_XYZ_BIT|TDFX_RGBA_BIT|TDFX_W_BIT)
108 #define TAG(x) x##_wg_fog
109 #include "tdfx_vbtmp.h"
110
111 #define IND (TDFX_XYZ_BIT|TDFX_RGBA_BIT|TDFX_W_BIT|TDFX_TEX0_BIT)
112 #define TAG(x) x##_wgt0
113 #include "tdfx_vbtmp.h"
114
115 #define IND (TDFX_XYZ_BIT|TDFX_RGBA_BIT|TDFX_W_BIT|TDFX_TEX0_BIT|TDFX_TEX1_BIT)
116 #define TAG(x) x##_wgt0t1
117 #include "tdfx_vbtmp.h"
118
119 #define IND (TDFX_XYZ_BIT|TDFX_RGBA_BIT|TDFX_W_BIT|TDFX_TEX0_BIT|TDFX_PTEX_BIT)
120 #define TAG(x) x##_wgpt0
121 #include "tdfx_vbtmp.h"
122
123 #define IND (TDFX_XYZ_BIT|TDFX_RGBA_BIT|TDFX_W_BIT|TDFX_TEX0_BIT|TDFX_TEX1_BIT|\
124 TDFX_PTEX_BIT)
125 #define TAG(x) x##_wgpt0t1
126 #include "tdfx_vbtmp.h"
127
128 #define IND (TDFX_RGBA_BIT)
129 #define TAG(x) x##_g
130 #include "tdfx_vbtmp.h"
131
132 #define IND (TDFX_TEX0_BIT)
133 #define TAG(x) x##_t0
134 #include "tdfx_vbtmp.h"
135
136 #define IND (TDFX_TEX0_BIT|TDFX_TEX1_BIT)
137 #define TAG(x) x##_t0t1
138 #include "tdfx_vbtmp.h"
139
140 #define IND (TDFX_RGBA_BIT|TDFX_TEX0_BIT)
141 #define TAG(x) x##_gt0
142 #include "tdfx_vbtmp.h"
143
144 #define IND (TDFX_RGBA_BIT|TDFX_TEX0_BIT|TDFX_TEX1_BIT)
145 #define TAG(x) x##_gt0t1
146 #include "tdfx_vbtmp.h"
147
148
149 /* fogc { */
150 #define IND (TDFX_XYZ_BIT|TDFX_RGBA_BIT|TDFX_W_BIT|TDFX_FOGC_BIT)
151 #define TAG(x) x##_wgf
152 #include "tdfx_vbtmp.h"
153
154 #define IND (TDFX_XYZ_BIT|TDFX_RGBA_BIT|TDFX_W_BIT|TDFX_TEX0_BIT|TDFX_FOGC_BIT)
155 #define TAG(x) x##_wgt0f
156 #include "tdfx_vbtmp.h"
157
158 #define IND (TDFX_XYZ_BIT|TDFX_RGBA_BIT|TDFX_W_BIT|TDFX_TEX0_BIT|TDFX_TEX1_BIT|TDFX_FOGC_BIT)
159 #define TAG(x) x##_wgt0t1f
160 #include "tdfx_vbtmp.h"
161
162 #define IND (TDFX_XYZ_BIT|TDFX_RGBA_BIT|TDFX_W_BIT|TDFX_TEX0_BIT|TDFX_PTEX_BIT|TDFX_FOGC_BIT)
163 #define TAG(x) x##_wgpt0f
164 #include "tdfx_vbtmp.h"
165
166 #define IND (TDFX_XYZ_BIT|TDFX_RGBA_BIT|TDFX_W_BIT|TDFX_TEX0_BIT|TDFX_TEX1_BIT|\
167 TDFX_PTEX_BIT|TDFX_FOGC_BIT)
168 #define TAG(x) x##_wgpt0t1f
169 #include "tdfx_vbtmp.h"
170 /* fogc } */
171
172
173 static void init_setup_tab( void )
174 {
175 init_wg();
176 init_wg_fog();
177 init_wgt0();
178 init_wgt0t1();
179 init_wgpt0();
180 init_wgpt0t1();
181
182 init_g();
183 init_t0();
184 init_t0t1();
185 init_gt0();
186 init_gt0t1();
187
188 /* fogcoord */
189 init_wgf();
190 init_wgt0f();
191 init_wgt0t1f();
192 init_wgpt0f();
193 init_wgpt0t1f();
194 }
195
196
197 void tdfxPrintSetupFlags(char *msg, GLuint flags )
198 {
199 fprintf(stderr, "%s(%x): %s%s%s%s%s%s\n",
200 msg,
201 (int)flags,
202 (flags & TDFX_XYZ_BIT) ? " xyz," : "",
203 (flags & TDFX_W_BIT) ? " w," : "",
204 (flags & TDFX_RGBA_BIT) ? " rgba," : "",
205 (flags & TDFX_TEX0_BIT) ? " tex-0," : "",
206 (flags & TDFX_TEX1_BIT) ? " tex-1," : "",
207 (flags & TDFX_FOGC_BIT) ? " fogc," : "");
208 }
209
210
211
212 void tdfxCheckTexSizes( GLcontext *ctx )
213 {
214 TNLcontext *tnl = TNL_CONTEXT(ctx);
215 tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx );
216
217 if (!setup_tab[fxMesa->SetupIndex].check_tex_sizes(ctx)) {
218 GLuint ind = fxMesa->SetupIndex |= (TDFX_PTEX_BIT|TDFX_RGBA_BIT);
219
220 /* Tdfx handles projective textures nicely; just have to change
221 * up to the new vertex format.
222 */
223 if (setup_tab[ind].vertex_format != fxMesa->vertexFormat) {
224 FLUSH_BATCH(fxMesa);
225 fxMesa->dirty |= TDFX_UPLOAD_VERTEX_LAYOUT;
226 fxMesa->vertexFormat = setup_tab[ind].vertex_format;
227
228 /* This is required as we have just changed the vertex
229 * format, so the interp and copy routines must also change.
230 * In the unfilled and twosided cases we are using the
231 * swrast_setup ones anyway, so leave them in place.
232 */
233 if (!(ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) {
234 tnl->Driver.Render.Interp = setup_tab[fxMesa->SetupIndex].interp;
235 tnl->Driver.Render.CopyPV = setup_tab[fxMesa->SetupIndex].copy_pv;
236 }
237 }
238 }
239 }
240
241
242 void tdfxBuildVertices( GLcontext *ctx, GLuint start, GLuint end,
243 GLuint newinputs )
244 {
245 tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx );
246 tdfxVertex *v = fxMesa->verts + start;
247
248 newinputs |= fxMesa->SetupNewInputs;
249 fxMesa->SetupNewInputs = 0;
250
251 if (!newinputs)
252 return;
253
254 if (newinputs & VERT_BIT_POS) {
255 setup_tab[fxMesa->SetupIndex].emit( ctx, start, end, v );
256 } else {
257 GLuint ind = 0;
258
259 if (newinputs & VERT_BIT_COLOR0)
260 ind |= TDFX_RGBA_BIT;
261
262 if (newinputs & VERT_BIT_FOG)
263 ind |= TDFX_FOGC_BIT;
264
265 if (newinputs & VERT_BIT_TEX0)
266 ind |= TDFX_TEX0_BIT;
267
268 if (newinputs & VERT_BIT_TEX1)
269 ind |= TDFX_TEX0_BIT|TDFX_TEX1_BIT;
270
271 if (fxMesa->SetupIndex & TDFX_PTEX_BIT)
272 ind = ~0;
273
274 ind &= fxMesa->SetupIndex;
275
276 if (ind) {
277 setup_tab[ind].emit( ctx, start, end, v );
278 }
279 }
280 }
281
282
283 void tdfxChooseVertexState( GLcontext *ctx )
284 {
285 TNLcontext *tnl = TNL_CONTEXT(ctx);
286 tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx );
287 GLuint ind = TDFX_XYZ_BIT|TDFX_RGBA_BIT;
288
289 fxMesa->tmu_source[0] = 0;
290 fxMesa->tmu_source[1] = 1;
291
292 if (ctx->Texture._EnabledUnits & 0x2) {
293 if (ctx->Texture._EnabledUnits & 0x1) {
294 ind |= TDFX_TEX1_BIT;
295 }
296 ind |= TDFX_W_BIT|TDFX_TEX0_BIT;
297 fxMesa->tmu_source[0] = 1;
298 fxMesa->tmu_source[1] = 0;
299 } else if (ctx->Texture._EnabledUnits & 0x1) {
300 /* unit 0 enabled */
301 ind |= TDFX_W_BIT|TDFX_TEX0_BIT;
302 } else if (fxMesa->Fog.Mode != GR_FOG_DISABLE) {
303 ind |= TDFX_W_BIT;
304 }
305
306 if (fxMesa->Fog.Mode == GR_FOG_WITH_TABLE_ON_FOGCOORD_EXT) {
307 ind |= TDFX_FOGC_BIT;
308 }
309
310 fxMesa->SetupIndex = ind;
311
312 if (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED)) {
313 tnl->Driver.Render.Interp = interp_extras;
314 tnl->Driver.Render.CopyPV = copy_pv_extras;
315 } else {
316 tnl->Driver.Render.Interp = setup_tab[ind].interp;
317 tnl->Driver.Render.CopyPV = setup_tab[ind].copy_pv;
318 }
319
320 if (setup_tab[ind].vertex_format != fxMesa->vertexFormat) {
321 FLUSH_BATCH(fxMesa);
322 fxMesa->dirty |= TDFX_UPLOAD_VERTEX_LAYOUT;
323 fxMesa->vertexFormat = setup_tab[ind].vertex_format;
324 }
325 }
326
327
328
329 void tdfxInitVB( GLcontext *ctx )
330 {
331 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
332 GLuint size = TNL_CONTEXT(ctx)->vb.Size;
333 static int firsttime = 1;
334 if (firsttime) {
335 init_setup_tab();
336 firsttime = 0;
337 }
338
339 fxMesa->verts = ALIGN_MALLOC(size * sizeof(tdfxVertex), 32);
340 fxMesa->vertexFormat = TDFX_LAYOUT_TINY;
341 fxMesa->SetupIndex = TDFX_XYZ_BIT|TDFX_RGBA_BIT;
342 }
343
344
345 void tdfxFreeVB( GLcontext *ctx )
346 {
347 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
348 if (fxMesa->verts) {
349 ALIGN_FREE(fxMesa->verts);
350 fxMesa->verts = 0;
351 }
352 }