GL_INTENSITY case was incorrect in extract_float_rgba()
[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 TNLcontext *tnl = TNL_CONTEXT(ctx);
294 fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
295
296 if (!fxMesa->is_in_hardware)
297 tnl->Driver.BuildProjectedVertices = _swsetup_BuildProjectedVertices;
298 else {
299 GLuint setupindex = SETUP_XYZW;
300
301 fxMesa->tmu_source[0] = 0;
302 fxMesa->tmu_source[1] = 1;
303 fxMesa->tex_dest[0] = SETUP_TMU0;
304 fxMesa->tex_dest[1] = SETUP_TMU1;
305
306 /* For flat and two-side-lit triangles, colors will always be added
307 * to vertices in the triangle functions. Vertices will *always*
308 * have rbga values, but only sometimes will they come from here.
309 */
310 if ((ctx->_TriangleCaps & (DD_FLATSHADE | DD_TRI_LIGHT_TWOSIDE)) == 0)
311 setupindex |= SETUP_RGBA;
312
313 if (ctx->Texture._ReallyEnabled & TEXTURE0_2D)
314 setupindex |= SETUP_TMU0;
315
316 if (ctx->Texture._ReallyEnabled & TEXTURE1_2D) {
317 if ((ctx->Texture._ReallyEnabled & TEXTURE0_2D) == 0) {
318 fxMesa->tmu_source[0] = 1;
319 fxMesa->tex_dest[0] = SETUP_TMU1;
320 fxMesa->tmu_source[1] = 0;
321 fxMesa->tex_dest[1] = SETUP_TMU0;
322 setupindex |= SETUP_TMU0;
323 }
324 else {
325 setupindex |= SETUP_TMU1;
326 }
327 }
328
329 if (MESA_VERBOSE & (VERBOSE_DRIVER | VERBOSE_PIPELINE | VERBOSE_STATE))
330 fxPrintSetupFlags("fxmesa: vertex setup function", setupindex);
331
332 fxMesa->setupindex = setupindex;
333 tnl->Driver.BuildProjectedVertices = fx_BuildProjVerts;
334 }
335 tnl->Driver.BuildProjectedVertices(ctx, start, count, newinputs);
336 }
337
338
339 void
340 fx_BuildProjVerts(GLcontext * ctx, GLuint start, GLuint count,
341 GLuint newinputs)
342 {
343 fxMesaContext fxMesa = FX_CONTEXT(ctx);
344 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
345
346 if (newinputs == ~0) {
347 /* build interpolated vertices */
348 setupfuncs[fxMesa->setupindex] (ctx, start, count);
349 }
350 else {
351 GLuint ind = fxMesa->setup_gone;
352 fxMesa->setup_gone = 0;
353
354 if (newinputs & VERT_CLIP)
355 ind = fxMesa->setupindex; /* clipmask has potentially changed */
356 else {
357 if (newinputs & VERT_TEX0)
358 ind |= fxMesa->tex_dest[0];
359
360 if (newinputs & VERT_TEX1)
361 ind |= fxMesa->tex_dest[1];
362
363 if (newinputs & VERT_RGBA)
364 ind |= SETUP_RGBA;
365
366 ind &= fxMesa->setupindex;
367 }
368
369 if (ind) {
370 if (fxMesa->new_state)
371 fxSetupFXUnits(ctx); /* why? */
372
373 if (VB->importable_data & newinputs)
374 VB->import_data(ctx, VB->importable_data & newinputs,
375 VEC_BAD_STRIDE);
376
377 setupfuncs[ind] (ctx, start, count);
378 }
379 }
380 }
381
382 void
383 fxAllocVB(GLcontext * ctx)
384 {
385 fxMesaContext fxMesa = FX_CONTEXT(ctx);
386 TNLcontext *tnl = TNL_CONTEXT(ctx);
387 fxMesa->verts = ALIGN_MALLOC(tnl->vb.Size * sizeof(fxMesa->verts[0]), 32);
388 }
389
390 void
391 fxFreeVB(GLcontext * ctx)
392 {
393 fxMesaContext fxMesa = FX_CONTEXT(ctx);
394 if (fxMesa->verts)
395 ALIGN_FREE(fxMesa->verts);
396 fxMesa->verts = 0;
397 }
398
399
400 #else
401
402
403 /*
404 * Need this to provide at least one external definition.
405 */
406
407 extern int gl_fx_dummy_function_vsetup(void);
408 int
409 gl_fx_dummy_function_vsetup(void)
410 {
411 return 0;
412 }
413
414 #endif /* FX */