fixed a bunch of g++ warnings/errors. Compiling with g++ can help find lots of poten...
[mesa.git] / src / mesa / drivers / glide / fxvb.c
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 3.3
5 *
6 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions 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 MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 *
26 * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
27 * terms stated above.
28 *
29 * Author:
30 * Keith Whitwell <keith@precisioninsight.com>
31 */
32
33
34 /* fxvsetup.c - 3Dfx VooDoo vertices setup functions */
35
36
37 #ifdef HAVE_CONFIG_H
38 #include "conf.h"
39 #endif
40
41 #if defined(FX)
42
43 #include "fxdrv.h"
44 #include "mmath.h"
45 #include "swrast_setup/swrast_setup.h"
46
47 #include "tnl/t_context.h"
48 #include "tnl/t_pipeline.h"
49
50
51 void
52 fxPrintSetupFlags(const char *msg, GLuint flags)
53 {
54 fprintf(stderr, "%s: %d %s%s%s%s%s\n",
55 msg,
56 flags,
57 (flags & SETUP_XYZW) ? " xyzw," : "",
58 (flags & SETUP_SNAP) ? " snap," : "",
59 (flags & SETUP_RGBA) ? " rgba," : "",
60 (flags & SETUP_TMU0) ? " tmu0," : "",
61 (flags & SETUP_TMU1) ? " tmu1," : "");
62 }
63
64 static void
65 project_texcoords(fxVertex * v,
66 struct vertex_buffer *VB,
67 GLuint tmu_nr, GLuint tc_nr, GLuint start, GLuint count)
68 {
69 GrTmuVertex *tmu = &(v->v.tmuvtx[tmu_nr]);
70 GLvector4f *vec = VB->TexCoordPtr[tc_nr];
71
72 GLuint i;
73 GLuint stride = vec->stride;
74 GLfloat *data = VEC_ELT(vec, GLfloat, start);
75
76 for (i = start; i < count; i++, STRIDE_F(data, stride), v++) {
77 tmu->oow = v->v.oow * data[3];
78 tmu = (GrTmuVertex *) ((char *) tmu + sizeof(fxVertex));
79 }
80 }
81
82
83 static void
84 copy_w(fxVertex * v,
85 struct vertex_buffer *VB, GLuint tmu_nr, GLuint start, GLuint count)
86 {
87 GrTmuVertex *tmu = &(v->v.tmuvtx[tmu_nr]);
88 GLuint i;
89
90 for (i = start; i < count; i++, v++) {
91 tmu->oow = v->v.oow;
92 tmu = (GrTmuVertex *) ((char *) tmu + sizeof(fxVertex));
93 }
94 }
95
96 /* need to compute W values for fogging purposes
97 */
98 static void
99 fx_fake_fog_w(GLcontext * ctx,
100 fxVertex * verts,
101 struct vertex_buffer *VB, GLuint start, GLuint end)
102 {
103 const GLfloat m10 = ctx->ProjectionMatrix.m[10];
104 const GLfloat m14 = ctx->ProjectionMatrix.m[14];
105 GLfloat(*clip)[4] = VB->ClipPtr->data;
106 GLubyte *clipmask = VB->ClipMask;
107 GLuint i;
108
109 for (i = start; i < end; i++) {
110 if (clipmask[i] == 0) {
111 verts[i].v.oow = -m10 / (clip[i][2] - m14); /* -1/zEye */
112 }
113 }
114 }
115
116
117
118 static tfxSetupFunc setupfuncs[MAX_SETUP];
119
120
121 #define IND (SETUP_XYZW)
122 #define INPUTS (VERT_CLIP)
123 #define NAME fxsetupXYZW
124 #include "fxvbtmp.h"
125
126 #define IND (SETUP_XYZW|SETUP_RGBA)
127 #define INPUTS (VERT_CLIP|VERT_RGBA)
128 #define NAME fxsetupXYZWRGBA
129 #include "fxvbtmp.h"
130
131 #define IND (SETUP_XYZW|SETUP_TMU0)
132 #define INPUTS (VERT_CLIP|VERT_TEX_ANY)
133 #define NAME fxsetupXYZWT0
134 #include "fxvbtmp.h"
135
136 #define IND (SETUP_XYZW|SETUP_TMU1)
137 #define INPUTS (VERT_CLIP|VERT_TEX_ANY)
138 #define NAME fxsetupXYZWT1
139 #include "fxvbtmp.h"
140
141 #define IND (SETUP_XYZW|SETUP_TMU1|SETUP_TMU0)
142 #define INPUTS (VERT_CLIP|VERT_TEX_ANY)
143 #define NAME fxsetupXYZWT0T1
144 #include "fxvbtmp.h"
145
146 #define IND (SETUP_XYZW|SETUP_TMU0|SETUP_RGBA)
147 #define INPUTS (VERT_CLIP|VERT_RGBA|VERT_TEX_ANY)
148 #define NAME fxsetupXYZWRGBAT0
149 #include "fxvbtmp.h"
150
151 #define IND (SETUP_XYZW|SETUP_TMU1|SETUP_RGBA)
152 #define INPUTS (VERT_CLIP|VERT_RGBA|VERT_TEX_ANY)
153 #define NAME fxsetupXYZWRGBAT1
154 #include "fxvbtmp.h"
155
156 #define IND (SETUP_XYZW|SETUP_TMU1|SETUP_TMU0|SETUP_RGBA)
157 #define INPUTS (VERT_CLIP|VERT_RGBA|VERT_TEX_ANY)
158 #define NAME fxsetupXYZWRGBAT0T1
159 #include "fxvbtmp.h"
160
161
162 #define IND (SETUP_XYZW|SETUP_SNAP)
163 #define INPUTS (VERT_CLIP)
164 #define NAME fxsetupXYZW_SNAP
165 #include "fxvbtmp.h"
166
167 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_RGBA)
168 #define INPUTS (VERT_CLIP|VERT_RGBA)
169 #define NAME fxsetupXYZW_SNAP_RGBA
170 #include "fxvbtmp.h"
171
172 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_TMU0)
173 #define INPUTS (VERT_CLIP|VERT_TEX_ANY)
174 #define NAME fxsetupXYZW_SNAP_T0
175 #include "fxvbtmp.h"
176
177 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_TMU1)
178 #define INPUTS (VERT_CLIP|VERT_TEX_ANY)
179 #define NAME fxsetupXYZW_SNAP_T1
180 #include "fxvbtmp.h"
181
182 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_TMU1|SETUP_TMU0)
183 #define INPUTS (VERT_CLIP|VERT_TEX_ANY)
184 #define NAME fxsetupXYZW_SNAP_T0T1
185 #include "fxvbtmp.h"
186
187 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_TMU0|SETUP_RGBA)
188 #define INPUTS (VERT_CLIP|VERT_RGBA|VERT_TEX_ANY)
189 #define NAME fxsetupXYZW_SNAP_RGBAT0
190 #include "fxvbtmp.h"
191
192 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_TMU1|SETUP_RGBA)
193 #define INPUTS (VERT_CLIP|VERT_RGBA|VERT_TEX_ANY)
194 #define NAME fxsetupXYZW_SNAP_RGBAT1
195 #include "fxvbtmp.h"
196
197 #define IND (SETUP_XYZW|SETUP_SNAP|SETUP_TMU1|SETUP_TMU0|SETUP_RGBA)
198 #define INPUTS (VERT_CLIP|VERT_RGBA|VERT_TEX_ANY)
199 #define NAME fxsetupXYZW_SNAP_RGBAT0T1
200 #include "fxvbtmp.h"
201
202
203
204 #define IND (SETUP_RGBA)
205 #define INPUTS (VERT_RGBA)
206 #define NAME fxsetupRGBA
207 #include "fxvbtmp.h"
208
209 #define IND (SETUP_TMU0)
210 #define INPUTS (VERT_TEX_ANY)
211 #define NAME fxsetupT0
212 #include "fxvbtmp.h"
213
214 #define IND (SETUP_TMU1)
215 #define INPUTS (VERT_TEX_ANY)
216 #define NAME fxsetupT1
217 #include "fxvbtmp.h"
218
219 #define IND (SETUP_TMU1|SETUP_TMU0)
220 #define INPUTS (VERT_TEX_ANY)
221 #define NAME fxsetupT0T1
222 #include "fxvbtmp.h"
223
224 #define IND (SETUP_TMU0|SETUP_RGBA)
225 #define INPUTS (VERT_RGBA|VERT_TEX_ANY)
226 #define NAME fxsetupRGBAT0
227 #include "fxvbtmp.h"
228
229 #define IND (SETUP_TMU1|SETUP_RGBA)
230 #define INPUTS (VERT_RGBA|VERT_TEX_ANY)
231 #define NAME fxsetupRGBAT1
232 #include "fxvbtmp.h"
233
234 #define IND (SETUP_TMU1|SETUP_TMU0|SETUP_RGBA)
235 #define INPUTS (VERT_RGBA|VERT_TEX_ANY)
236 #define NAME fxsetupRGBAT0T1
237 #include "fxvbtmp.h"
238
239
240 static void
241 fxsetup_invalid(GLcontext * ctx, GLuint start, GLuint end)
242 {
243 fprintf(stderr, "fxMesa: invalid setup function\n");
244 (void) (ctx && start && end);
245 }
246
247
248 void
249 fxDDSetupInit(void)
250 {
251 GLuint i;
252 for (i = 0; i < Elements(setupfuncs); i++)
253 setupfuncs[i] = fxsetup_invalid;
254
255 setupfuncs[SETUP_XYZW] = fxsetupXYZW;
256 setupfuncs[SETUP_XYZW | SETUP_RGBA] = fxsetupXYZWRGBA;
257 setupfuncs[SETUP_XYZW | SETUP_TMU0] = fxsetupXYZWT0;
258 setupfuncs[SETUP_XYZW | SETUP_TMU1] = fxsetupXYZWT1;
259 setupfuncs[SETUP_XYZW | SETUP_TMU0 | SETUP_RGBA] = fxsetupXYZWRGBAT0;
260 setupfuncs[SETUP_XYZW | SETUP_TMU1 | SETUP_RGBA] = fxsetupXYZWRGBAT1;
261 setupfuncs[SETUP_XYZW | SETUP_TMU1 | SETUP_TMU0] = fxsetupXYZWT0T1;
262 setupfuncs[SETUP_XYZW | SETUP_TMU1 | SETUP_TMU0 | SETUP_RGBA] =
263 fxsetupXYZWRGBAT0T1;
264
265 setupfuncs[SETUP_XYZW | SETUP_SNAP] = fxsetupXYZW_SNAP;
266 setupfuncs[SETUP_XYZW | SETUP_SNAP | SETUP_RGBA] = fxsetupXYZW_SNAP_RGBA;
267 setupfuncs[SETUP_XYZW | SETUP_SNAP | SETUP_TMU0] = fxsetupXYZW_SNAP_T0;
268 setupfuncs[SETUP_XYZW | SETUP_SNAP | SETUP_TMU1] = fxsetupXYZW_SNAP_T1;
269 setupfuncs[SETUP_XYZW | SETUP_SNAP | SETUP_TMU0 | SETUP_RGBA] =
270 fxsetupXYZW_SNAP_RGBAT0;
271 setupfuncs[SETUP_XYZW | SETUP_SNAP | SETUP_TMU1 | SETUP_RGBA] =
272 fxsetupXYZW_SNAP_RGBAT1;
273 setupfuncs[SETUP_XYZW | SETUP_SNAP | SETUP_TMU1 | SETUP_TMU0] =
274 fxsetupXYZW_SNAP_T0T1;
275 setupfuncs[SETUP_XYZW | SETUP_SNAP | SETUP_TMU1 | SETUP_TMU0 | SETUP_RGBA]
276 = fxsetupXYZW_SNAP_RGBAT0T1;
277
278 setupfuncs[SETUP_RGBA] = fxsetupRGBA;
279 setupfuncs[SETUP_TMU0] = fxsetupT0;
280 setupfuncs[SETUP_TMU1] = fxsetupT1;
281 setupfuncs[SETUP_TMU1 | SETUP_TMU0] = fxsetupT0T1;
282 setupfuncs[SETUP_TMU0 | SETUP_RGBA] = fxsetupRGBAT0;
283 setupfuncs[SETUP_TMU1 | SETUP_RGBA] = fxsetupRGBAT1;
284 setupfuncs[SETUP_TMU1 | SETUP_TMU0 | SETUP_RGBA] = fxsetupRGBAT0T1;
285 }
286
287
288
289 void
290 fx_validate_BuildProjVerts(GLcontext * ctx, GLuint start, GLuint count,
291 GLuint newinputs)
292 {
293 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
294
295 if (!fxMesa->is_in_hardware)
296 ctx->Driver.BuildProjectedVertices = _swsetup_BuildProjectedVertices;
297 else {
298 GLuint setupindex = SETUP_XYZW;
299
300 fxMesa->tmu_source[0] = 0;
301 fxMesa->tmu_source[1] = 1;
302 fxMesa->tex_dest[0] = SETUP_TMU0;
303 fxMesa->tex_dest[1] = SETUP_TMU1;
304
305 /* For flat and two-side-lit triangles, colors will always be added
306 * to vertices in the triangle functions. Vertices will *always*
307 * have rbga values, but only sometimes will they come from here.
308 */
309 if ((ctx->_TriangleCaps & (DD_FLATSHADE | DD_TRI_LIGHT_TWOSIDE)) == 0)
310 setupindex |= SETUP_RGBA;
311
312 if (ctx->Texture._ReallyEnabled & TEXTURE0_2D)
313 setupindex |= SETUP_TMU0;
314
315 if (ctx->Texture._ReallyEnabled & TEXTURE1_2D) {
316 if ((ctx->Texture._ReallyEnabled & TEXTURE0_2D) == 0) {
317 fxMesa->tmu_source[0] = 1;
318 fxMesa->tex_dest[0] = SETUP_TMU1;
319 fxMesa->tmu_source[1] = 0;
320 fxMesa->tex_dest[1] = SETUP_TMU0;
321 setupindex |= SETUP_TMU0;
322 }
323 else {
324 setupindex |= SETUP_TMU1;
325 }
326 }
327
328 if (MESA_VERBOSE & (VERBOSE_DRIVER | VERBOSE_PIPELINE | VERBOSE_STATE))
329 fxPrintSetupFlags("fxmesa: vertex setup function", setupindex);
330
331 fxMesa->setupindex = setupindex;
332 ctx->Driver.BuildProjectedVertices = fx_BuildProjVerts;
333 }
334 ctx->Driver.BuildProjectedVertices(ctx, start, count, newinputs);
335 }
336
337
338 void
339 fx_BuildProjVerts(GLcontext * ctx, GLuint start, GLuint count,
340 GLuint newinputs)
341 {
342 fxMesaContext fxMesa = FX_CONTEXT(ctx);
343 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
344
345 if (newinputs == ~0) {
346 /* build interpolated vertices */
347 setupfuncs[fxMesa->setupindex] (ctx, start, count);
348 }
349 else {
350 GLuint ind = fxMesa->setup_gone;
351 fxMesa->setup_gone = 0;
352
353 if (newinputs & VERT_CLIP)
354 ind = fxMesa->setupindex; /* clipmask has potentially changed */
355 else {
356 if (newinputs & VERT_TEX0)
357 ind |= fxMesa->tex_dest[0];
358
359 if (newinputs & VERT_TEX1)
360 ind |= fxMesa->tex_dest[1];
361
362 if (newinputs & VERT_RGBA)
363 ind |= SETUP_RGBA;
364
365 ind &= fxMesa->setupindex;
366 }
367
368 if (ind) {
369 if (fxMesa->new_state)
370 fxSetupFXUnits(ctx); /* why? */
371
372 if (VB->importable_data & newinputs)
373 VB->import_data(ctx, VB->importable_data & newinputs,
374 VEC_BAD_STRIDE);
375
376 setupfuncs[ind] (ctx, start, count);
377 }
378 }
379 }
380
381 void
382 fxAllocVB(GLcontext * ctx)
383 {
384 fxMesaContext fxMesa = FX_CONTEXT(ctx);
385 TNLcontext *tnl = TNL_CONTEXT(ctx);
386 fxMesa->verts = ALIGN_MALLOC(tnl->vb.Size * sizeof(fxMesa->verts[0]), 32);
387 }
388
389 void
390 fxFreeVB(GLcontext * ctx)
391 {
392 fxMesaContext fxMesa = FX_CONTEXT(ctx);
393 if (fxMesa->verts)
394 ALIGN_FREE(fxMesa->verts);
395 fxMesa->verts = 0;
396 }
397
398
399 #else
400
401
402 /*
403 * Need this to provide at least one external definition.
404 */
405
406 extern int gl_fx_dummy_function_vsetup(void);
407 int
408 gl_fx_dummy_function_vsetup(void)
409 {
410 return 0;
411 }
412
413 #endif /* FX */