Import s3virge and trident drivers. Not functional yet; no Makefile, no DRI-aware...
[mesa.git] / src / mesa / drivers / dri / trident / trident_tris.c
1 /*
2 * Copyright 2002 by Alan Hourihane, Sychdyn, North Wales, UK.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Alan Hourihane not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Alan Hourihane makes no representations
11 * about the suitability of this software for any purpose. It is provided
12 * "as is" without express or implied warranty.
13 *
14 * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 *
22 * Authors: Alan Hourihane, <alanh@fairlite.demon.co.uk>
23 *
24 * Trident CyberBladeXP driver.
25 *
26 */
27
28 #include "trident_context.h"
29 #include "trident_lock.h"
30 #include "tnl/tnl.h"
31 #include "tnl/t_context.h"
32 #include "tnl/t_pipeline.h"
33 #include "swrast/swrast.h"
34
35 static int first = 1;
36
37 typedef struct reg {
38 int addr;
39 int data;
40 } RegData;
41
42 RegData initRegData[]={
43 {0x2804, 0x19980824},
44 {0x2F70, 0x46455858},
45 {0x2F74, 0x41584998},
46 {0x2F00, 0x00000000},
47 {0x2F04, 0x80000800},
48 {0x2F08, 0x00550200},
49 {0x2F40, 0x00000001},
50 {0x2F40, 0x00000001},
51 {0x2F44, 0x00830097},
52 {0x2F48, 0x0087009F},
53 {0x2F4C, 0x00BF0003},
54 {0x2F50, 0xF00B6C1B},
55 {0x2C04, 0x00000000},
56 {0x2D00, 0x00000080},
57 {0x2D00, 0x00000000},
58 {0x2DD4, 0x00100000},
59 {0x2DD4, 0x00100010},
60 {0x2DD8, 0x00100000},
61 {0x2DD8, 0x00100010},
62 {0x2C88, 0xFFFFFFFF},
63 {0x2C94 , 0xFFFFFFFF},
64 {0x281C, 0x00008000},
65 {0x2C80, 0x00000000},
66 {0x2C80, 0x00000000},
67 {0x2C80 , 0x00008000},
68 {0x2C00 , 0x00000000},
69 {0x2C04 , 0x00000000},
70 {0x2C08 , 0x00000000},
71 {0x2C0C , 0x00000000},
72 {0x2C10 , 0x00000000},
73 {0x2C14 , 0x00000000},
74 {0x2C18 , 0x00000000},
75 {0x2C1C , 0x00000000},
76 {0x2C20 , 0x00000000},
77 {0x2C24 , 0x00000000},
78 {0x2C2C , 0x00000000},
79 {0x2C30 , 0x00000000},
80 {0x2C34 , 0x00000000},
81 {0x2C38 , 0x00000000},
82 {0x2C3C , 0x00000000},
83 {0x2C40 , 0x00000000},
84 {0x2C44 , 0x00000000},
85 {0x2C48 , 0x00000000},
86 {0x2C4C , 0x00000000},
87 {0x2C50 , 0x00000000},
88 {0x2C54 , 0x00000000},
89 {0x2C58 , 0x00000000},
90 {0x2C5C , 0x00000000},
91 {0x2C60 , 0x00000000},
92 {0x2C64 , 0x00000000},
93 {0x2C68 , 0x00000000},
94 {0x2C6C , 0x00000000},
95 {0x2C70 , 0x00000000},
96 {0x2C74 , 0x00000000},
97 {0x2C78 , 0x00000000},
98 {0x2C7C , 0x00000000},
99 {0x2C80 , 0x00008000},
100 {0x2C84 , 0x00000000},
101 {0x2C88 , 0xFFFFFFFF},
102 {0x2C8C , 0x00000000},
103 {0x2C90 , 0x00000000},
104 {0x2C94 , 0xFFFFFFFF},
105 {0x2C98 , 0x00000000},
106 {0x2C9C , 0x00000000},
107 {0x2CA0 , 0x00000000},
108 {0x2CA4 , 0x00000000},
109 {0x2CA8 , 0x00000000},
110 {0x2CAC , 0x00000000},
111 {0x2CB0 , 0x00000000},
112 {0x2CB4 , 0x00000000},
113 {0x2CB8 , 0x00000000},
114 {0x2CBC , 0x00000000},
115 {0x2CC0 , 0x00000000},
116 {0x2CC4 , 0x00000000},
117 {0x2CC8 , 0x00000000},
118 {0x2CCC , 0x00000000},
119 {0x2CD0 , 0x00000000},
120 {0x2CD4 , 0x00000000},
121 {0x2CD8 , 0x00000000},
122 {0x2CDC , 0x00000000},
123 {0x2CE0 , 0x00000000},
124 {0x2CE4 , 0x00000000},
125 {0x2CE8 , 0x00000000},
126 {0x2CEC , 0x00000000},
127 {0x2CF0 , 0x00000000},
128 {0x2CF4 , 0x00000000},
129 {0x2CF8 , 0x00000000},
130 {0x2CFC , 0x00000000},
131 {0x2D00 , 0x00000000},
132 {0x2D04 , 0x00000000},
133 {0x2D08 , 0x00000000},
134 {0x2D0C , 0x00000000},
135 {0x2D10 , 0x00000000},
136 {0x2D14 , 0x00000000},
137 {0x2D18 , 0x00000000},
138 {0x2D1C , 0x00000000},
139 {0x2D20 , 0x00000000},
140 {0x2D24 , 0x00000000},
141 {0x2D28 , 0x00000000},
142 {0x2D2C , 0x00000000},
143 {0x2D30 , 0x00000000},
144 {0x2D34 , 0x00000000},
145 {0x2D38 , 0x00000000},
146 {0x2D3C , 0x00000000},
147 {0x2D40 , 0x00000000},
148 {0x2D44 , 0x00000000},
149 {0x2D48 , 0x00000000},
150 {0x2D4C , 0x00000000},
151 {0x2D50 , 0x00000000},
152 {0x2D54 , 0x00000000},
153 {0x2D58 , 0x00000000},
154 {0x2D5C , 0x00000000},
155 {0x2D60 , 0x00000000},
156 {0x2D64 , 0x00000000},
157 {0x2D68 , 0x00000000},
158 {0x2D6C , 0x00000000},
159 {0x2D70 , 0x00000000},
160 {0x2D74 , 0x00000000},
161 {0x2D78 , 0x00000000},
162 {0x2D7C , 0x00000000},
163 {0x2D80 , 0x00000000},
164 {0x2D84 , 0x00000000},
165 {0x2D88 , 0x00000000},
166 {0x2D8C , 0x00000000},
167 {0x2D90 , 0x00000000},
168 {0x2D94 , 0x00000000},
169 {0x2D98 , 0x00000000},
170 {0x2D9C , 0x00000000},
171 {0x2DA0 , 0x00000000},
172 {0x2DA4 , 0x00000000},
173 {0x2DA8 , 0x00000000},
174 {0x2DAC , 0x00000000},
175 {0x2DB0 , 0x00000000},
176 {0x2DB4 , 0x00000000},
177 {0x2DB8 , 0x00000000},
178 {0x2DBC , 0x00000000},
179 {0x2DC0 , 0x00000000},
180 {0x2DC4 , 0x00000000},
181 {0x2DC8 , 0x00000000},
182 {0x2DCC , 0x00000000},
183 {0x2DD0 , 0x00000000},
184 {0x2DD4 , 0x00100010},
185 {0x2DD8 , 0x00100010},
186 {0x2DDC , 0x00000000},
187 {0x2DE0 , 0x00000000},
188 {0x2DE4 , 0x00000000},
189 {0x2DE8 , 0x00000000},
190 {0x2DEC , 0x00000000},
191 {0x2DF0 , 0x00000000},
192 {0x2DF4 , 0x00000000},
193 {0x2DF8 , 0x00000000},
194 {0x2DFC , 0x00000000},
195 {0x2E00 , 0x00000000},
196 {0x2E04 , 0x00000000},
197 {0x2E08 , 0x00000000},
198 {0x2E0C , 0x00000000},
199 {0x2E10 , 0x00000000},
200 {0x2E14 , 0x00000000},
201 {0x2E18 , 0x00000000},
202 {0x2E1C , 0x00000000},
203 {0x2E20 , 0x00000000},
204 {0x2E24 , 0x00000000},
205 {0x2E28 , 0x00000000},
206 {0x2E2C , 0x00000000},
207 {0x2E30 , 0x00000000},
208 {0x2E34 , 0x00000000},
209 {0x2E38 , 0x00000000},
210 {0x2E3C , 0x00000000},
211 {0x2E40 , 0x00000000},
212 {0x2E44 , 0x00000000},
213 {0x2E48 , 0x00000000},
214 {0x2E4C , 0x00000000},
215 {0x2E50 , 0x00000000},
216 {0x2E54 , 0x00000000},
217 {0x2E58 , 0x00000000},
218 {0x2E5C , 0x00000000},
219 {0x2E60 , 0x00000000},
220 {0x2E64 , 0x00000000},
221 {0x2E68 , 0x00000000},
222 {0x2E6C , 0x00000000},
223 {0x2E70 , 0x00000000},
224 {0x2E74 , 0x00000000},
225 {0x2E78 , 0x00000000},
226 {0x2E7C , 0x00000000},
227 {0x2E80 , 0x00000000},
228 {0x2E84 , 0x00000000},
229 {0x2E88 , 0x00000000},
230 {0x2E8C , 0x00000000},
231 {0x2E90 , 0x00000000},
232 {0x2E94 , 0x00000000},
233 {0x2E98 , 0x00000000},
234 {0x2E9C , 0x00000000},
235 {0x2EA0 , 0x00000000},
236 {0x2EA4 , 0x00000000},
237 {0x2EA8 , 0x00000000},
238 {0x2EAC , 0x00000000},
239 {0x2EB0 , 0x00000000},
240 {0x2EB4 , 0x00000000},
241 {0x2EB8 , 0x00000000},
242 {0x2EBC , 0x00000000},
243 {0x2EC0 , 0x00000000},
244 {0x2EC4 , 0x00000000},
245 {0x2EC8 , 0x00000000},
246 {0x2ECC , 0x00000000},
247 {0x2ED0 , 0x00000000},
248 {0x2ED4 , 0x00000000},
249 {0x2ED8 , 0x00000000},
250 {0x2EDC , 0x00000000},
251 {0x2EE0 , 0x00000000},
252 {0x2EE4 ,0x00000000},
253 {0x2EE8 ,0x00000000},
254 {0x2EEC , 0x00000000},
255 {0x2EF0 , 0x00000000},
256 {0x2EF4 , 0x00000000},
257 {0x2EF8 , 0x00000000},
258 {0x2EFC , 0x00000000},
259 /*{0x2F60 , 0x00000000},*/
260 };
261
262 int initRegDataNum=sizeof(initRegData)/sizeof(RegData);
263
264 typedef union {
265 unsigned int i;
266 float f;
267 } dmaBufRec, *dmaBuf;
268
269 void Init3D( tridentContextPtr tmesa )
270 {
271 unsigned char *MMIO = tmesa->tridentScreen->mmio.map;
272 int i;
273
274 for(i=0;i<initRegDataNum;++i)
275 MMIO_OUT32(MMIO, initRegData[i].addr, initRegData[i].data);
276 }
277
278 int DrawTriangle( tridentContextPtr tmesa)
279 {
280 volatile unsigned char *MMIO = tmesa->tridentScreen->mmio.map;
281 dmaBufRec clr;
282
283 printf("DRAW TRI\n");
284 Init3D(tmesa);
285
286 printf("ENGINE STATUS 0x%x\n",MMIO_IN32(MMIO, 0x2800));
287 MMIO_OUT32(MMIO, 0x002800, 0x00000000 );
288 #if 0
289 MMIO_OUT32(MMIO, 0x002368 , MMIO_IN32(MMIO,0x002368)|1 );
290 #endif
291
292 MMIO_OUT32(MMIO, 0x002C00 , 0x00000014 );
293 #if 0
294 MMIO_OUT32(MMIO, 0x002C04 , 0x0A8004C0 );
295 #else
296 MMIO_OUT32(MMIO, 0x002C04 , 0x0A8000C0 );
297 #endif
298
299 #if 0
300 MMIO_OUT32(MMIO, 0x002C08 , 0x00000000 );
301 MMIO_OUT32(MMIO, 0x002C0C , 0xFFCCCCCC );
302 MMIO_OUT32(MMIO, 0x002C10 , 0x3F800000 );
303 MMIO_OUT32(MMIO, 0x002C14 , 0x3D0D3DCB );
304 MMIO_OUT32(MMIO, 0x002C2C , 0x70000000 );
305 MMIO_OUT32(MMIO, 0x002C24 , 0x00202C00 );
306 MMIO_OUT32(MMIO, 0x002C28 , 0xE0002500 );
307 MMIO_OUT32(MMIO, 0x002C30 , 0x00000000 );
308 MMIO_OUT32(MMIO, 0x002C34 , 0xE0000000 );
309 MMIO_OUT32(MMIO, 0x002C38 , 0x00000000 );
310 #endif
311
312 MMIO_OUT32(MMIO, 0x002C50 , 0x00000000 );
313 MMIO_OUT32(MMIO, 0x002C54 , 0x0C320C80 );
314 MMIO_OUT32(MMIO, 0x002C50 , 0x00000000 );
315 MMIO_OUT32(MMIO, 0x002C54 , 0x0C320C80 );
316 MMIO_OUT32(MMIO, 0x002C80 , 0x20008258 );
317 MMIO_OUT32(MMIO, 0x002C84 , 0x20000320 );
318 MMIO_OUT32(MMIO, 0x002C94 , 0xFFFFFFFF );
319
320 #if 0
321 MMIO_OUT32(MMIO, 0x002D00 , 0x00009009 );
322 MMIO_OUT32(MMIO, 0x002D38 , 0x00000000 );
323 MMIO_OUT32(MMIO, 0x002D94 , 0x20002000 );
324 MMIO_OUT32(MMIO, 0x002D50 , 0xf0000000 );
325 MMIO_OUT32(MMIO, 0x002D80 , 0x24002000 );
326 MMIO_OUT32(MMIO, 0x002D98 , 0x81000000 );
327 MMIO_OUT32(MMIO, 0x002DB0 , 0x81000000 );
328 MMIO_OUT32(MMIO, 0x002DC8 , 0x808000FF );
329 MMIO_OUT32(MMIO, 0x002DD4 , 0x02000200 );
330 MMIO_OUT32(MMIO, 0x002DD8 , 0x02000200 );
331 MMIO_OUT32(MMIO, 0x002D30 , 0x02092400 );
332 MMIO_OUT32(MMIO, 0x002D04 , 0x00102120 );
333 MMIO_OUT32(MMIO, 0x002D08 , 0xFFFFFFFF );
334 MMIO_OUT32(MMIO, 0x002D0C , 0xF00010D0 );
335 MMIO_OUT32(MMIO, 0x002D10 , 0xC0000400 );
336 #endif
337
338 MMIO_OUT32(MMIO, 0x002814, 0x00000000 );
339 #if 0
340 MMIO_OUT32(MMIO, 0x002818 , 0x00036C20 );
341 #else
342 MMIO_OUT32(MMIO, 0x002818 , 0x00036020 );
343 #endif
344 MMIO_OUT32(MMIO, 0x00281C , 0x00098081 );
345
346 printf("first TRI\n");
347 clr.f = 5.0;
348 MMIO_OUT32(MMIO, 0x002820 , clr.i );
349 clr.f = 595.0;
350 MMIO_OUT32(MMIO, 0x002824 , clr.i );
351 clr.f = 1.0;
352 MMIO_OUT32(MMIO, 0x002828 , clr.i );
353 MMIO_OUT32(MMIO, 0x00282C , 0x00FF00 );
354 #if 0
355 clr.f = 0.0;
356 MMIO_OUT32(MMIO, 0x002830 , clr.i );
357 clr.f = 1.0;
358 MMIO_OUT32(MMIO, 0x002834 , clr.i );
359 #endif
360
361 clr.f = 5.0;
362 MMIO_OUT32(MMIO, 0x002820 , clr.i );
363 clr.f = 5.0;
364 MMIO_OUT32(MMIO, 0x002824 , clr.i );
365 clr.f = 1.0;
366 MMIO_OUT32(MMIO, 0x002828 , clr.i );
367 MMIO_OUT32(MMIO, 0x00282C , 0xFF0000 );
368 #if 0
369 clr.f = 0.0;
370 MMIO_OUT32(MMIO, 0x002830 , clr.i );
371 clr.f = 0.0;
372 MMIO_OUT32(MMIO, 0x002834 , clr.i );
373 #endif
374
375 clr.f = 395.0;
376 printf("0x%x\n",clr.i);
377 MMIO_OUT32(MMIO, 0x002820 , clr.i );
378 clr.f = 5.0;
379 MMIO_OUT32(MMIO, 0x002824 , clr.i );
380 clr.f = 1.0;
381 MMIO_OUT32(MMIO, 0x002828 , clr.i );
382 MMIO_OUT32(MMIO, 0x00282C , 0xFF );
383 #if 0
384 clr.f = 1.0;
385 MMIO_OUT32(MMIO, 0x002830 , clr.i );
386 clr.f = 0.0;
387 MMIO_OUT32(MMIO, 0x002834 , clr.i );
388 #endif
389
390 printf("sec TRI\n");
391 MMIO_OUT32(MMIO, 0x00281C , 0x00093980 );
392 clr.f = 395.0;
393 MMIO_OUT32(MMIO, 0x002820 , clr.i );
394 clr.f = 595.0;
395 MMIO_OUT32(MMIO, 0x002824 , clr.i );
396 clr.f = 1.0;
397 MMIO_OUT32(MMIO, 0x002828 , clr.i );
398 MMIO_OUT32(MMIO, 0x00282C , 0x00FF00 );
399 #if 0
400 clr.f = 1.0;
401 MMIO_OUT32(MMIO, 0x002830 , clr.i );
402 clr.f = 1.0;
403 MMIO_OUT32(MMIO, 0x002834 , clr.i );
404 #endif
405
406 #if 0
407 MMIO_OUT32(MMIO, 0x002368 , MMIO_IN32(MMIO,0x002368)&0xfffffffe );
408 #endif
409
410 printf("fin TRI\n");
411
412 return 0;
413 }
414
415 static INLINE void trident_draw_point(tridentContextPtr tmesa,
416 const tridentVertex *v0 )
417 {
418 unsigned char *MMIO = tmesa->tridentScreen->mmio.map;
419 }
420
421 static INLINE void trident_draw_line( tridentContextPtr tmesa,
422 const tridentVertex *v0,
423 const tridentVertex *v1 )
424 {
425 unsigned char *MMIO = tmesa->tridentScreen->mmio.map;
426 }
427
428 static INLINE void trident_draw_triangle( tridentContextPtr tmesa,
429 const tridentVertex *v0,
430 const tridentVertex *v1,
431 const tridentVertex *v2 )
432 {
433 }
434
435 static INLINE void trident_draw_quad( tridentContextPtr tmesa,
436 const tridentVertex *v0,
437 const tridentVertex *v1,
438 const tridentVertex *v2,
439 const tridentVertex *v3 )
440 {
441 GLuint vertsize = tmesa->vertex_size;
442 GLint coloridx = (vertsize > 4) ? 4 : 3;
443 unsigned char *MMIO = tmesa->tridentScreen->mmio.map;
444 int clr;
445 float *ftmp = (float *)(&clr);
446
447 if (tmesa->dirty)
448 tridentUploadHwStateLocked( tmesa );
449 #if 0
450 DrawTriangle(tmesa);
451 exit(0);
452 #else
453 #if 1
454 if (first) {
455 Init3D(tmesa);
456 #if 0
457 DrawTriangle(tmesa);
458 #endif
459 first = 0;
460 }
461 #endif
462
463 LOCK_HARDWARE( tmesa );
464
465 MMIO_OUT32(MMIO, 0x002C00 , 0x00000010 );
466 MMIO_OUT32(MMIO, 0x002C04 , 0x029C00C0 );
467
468 /* Z buffer */
469 MMIO_OUT32(MMIO, 0x002C24 , 0x00100000 /*| (tmesa->tridentScreen->depthOffset)*/ );
470 MMIO_OUT32(MMIO, 0x002C28 , 0xE0000000 | (tmesa->tridentScreen->depthPitch * 4) );
471
472 /* front buffer */
473 MMIO_OUT32(MMIO, 0x002C50 , 0x00000000 | (tmesa->drawOffset) );
474 MMIO_OUT32(MMIO, 0x002C54 , 0x0C320000 | (tmesa->drawPitch * 4) );
475
476 /* clipper */
477 MMIO_OUT32(MMIO, 0x002C80 , 0x20008000 | tmesa->tridentScreen->height );
478 MMIO_OUT32(MMIO, 0x002C84 , 0x20000000 | tmesa->tridentScreen->width );
479
480 /* writemask */
481 MMIO_OUT32(MMIO, 0x002C94 , 0xFFFFFFFF );
482
483 if (vertsize == 4) {
484 MMIO_OUT32(MMIO, 0x002818 , 0x0003A020 );
485 MMIO_OUT32(MMIO, 0x00281C , 0x00098021 );
486
487 *ftmp = v0->v.x;
488 MMIO_OUT32(MMIO, 0x002820 , clr );
489 *ftmp = v0->v.y;
490 MMIO_OUT32(MMIO, 0x002824 , clr );
491 *ftmp = v0->v.z;
492 MMIO_OUT32(MMIO, 0x002828 , clr );
493 #if 0
494 *ftmp = v0->v.w;
495 MMIO_OUT32(MMIO, 0x00282C , clr );
496 #endif
497 MMIO_OUT32(MMIO, 0x00282C , v0->ui[coloridx] );
498
499 *ftmp = v1->v.x;
500 MMIO_OUT32(MMIO, 0x002820 , clr );
501 *ftmp = v1->v.y;
502 MMIO_OUT32(MMIO, 0x002824 , clr );
503 *ftmp = v1->v.z;
504 MMIO_OUT32(MMIO, 0x002828 , clr );
505 #if 0
506 *ftmp = v1->v.w;
507 MMIO_OUT32(MMIO, 0x00282C , clr );
508 #endif
509 MMIO_OUT32(MMIO, 0x00282C , v1->ui[coloridx] );
510
511 *ftmp = v2->v.x;
512 MMIO_OUT32(MMIO, 0x002820 , clr );
513 *ftmp = v2->v.y;
514 MMIO_OUT32(MMIO, 0x002824 , clr );
515 *ftmp = v2->v.z;
516 MMIO_OUT32(MMIO, 0x002828 , clr );
517 #if 0
518 *ftmp = v2->v.w;
519 MMIO_OUT32(MMIO, 0x00282C , clr );
520 #endif
521 MMIO_OUT32(MMIO, 0x00282C , v2->ui[coloridx] );
522
523 MMIO_OUT32(MMIO, 0x00281C , 0x00093020 );
524 *ftmp = v3->v.x;
525 MMIO_OUT32(MMIO, 0x002820 , clr );
526 *ftmp = v3->v.y;
527 MMIO_OUT32(MMIO, 0x002824 , clr );
528 *ftmp = v3->v.z;
529 MMIO_OUT32(MMIO, 0x002828 , clr );
530 #if 0
531 *ftmp = v3->v.w;
532 MMIO_OUT32(MMIO, 0x00282C , clr );
533 #endif
534 MMIO_OUT32(MMIO, 0x00282C , v3->ui[coloridx] );
535
536 }
537 #endif
538
539 UNLOCK_HARDWARE( tmesa );
540 }
541 /***********************************************************************
542 * Rasterization fallback helpers *
543 ***********************************************************************/
544
545
546 /* This code is hit only when a mix of accelerated and unaccelerated
547 * primitives are being drawn, and only for the unaccelerated
548 * primitives.
549 */
550 static void
551 trident_fallback_quad( tridentContextPtr tmesa,
552 const tridentVertex *v0,
553 const tridentVertex *v1,
554 const tridentVertex *v2,
555 const tridentVertex *v3 )
556 {
557 GLcontext *ctx = tmesa->glCtx;
558 SWvertex v[4];
559 trident_translate_vertex( ctx, v0, &v[0] );
560 trident_translate_vertex( ctx, v1, &v[1] );
561 trident_translate_vertex( ctx, v2, &v[2] );
562 trident_translate_vertex( ctx, v3, &v[3] );
563 _swrast_Quad( ctx, &v[0], &v[1], &v[2], &v[3] );
564 }
565
566 static void
567 trident_fallback_tri( tridentContextPtr tmesa,
568 const tridentVertex *v0,
569 const tridentVertex *v1,
570 const tridentVertex *v2 )
571 {
572 GLcontext *ctx = tmesa->glCtx;
573 SWvertex v[3];
574 trident_translate_vertex( ctx, v0, &v[0] );
575 trident_translate_vertex( ctx, v1, &v[1] );
576 trident_translate_vertex( ctx, v2, &v[2] );
577 _swrast_Triangle( ctx, &v[0], &v[1], &v[2] );
578 }
579
580 static void
581 trident_fallback_line( tridentContextPtr tmesa,
582 const tridentVertex *v0,
583 const tridentVertex *v1 )
584 {
585 GLcontext *ctx = tmesa->glCtx;
586 SWvertex v[2];
587 trident_translate_vertex( ctx, v0, &v[0] );
588 trident_translate_vertex( ctx, v1, &v[1] );
589 _swrast_Line( ctx, &v[0], &v[1] );
590 }
591
592
593 static void
594 trident_fallback_point( tridentContextPtr tmesa,
595 const tridentVertex *v0 )
596 {
597 GLcontext *ctx = tmesa->glCtx;
598 SWvertex v[1];
599 trident_translate_vertex( ctx, v0, &v[0] );
600 _swrast_Point( ctx, &v[0] );
601 }
602
603 /***********************************************************************
604 * Macros for t_dd_tritmp.h to draw basic primitives *
605 ***********************************************************************/
606
607 #define TRI( a, b, c ) \
608 do { \
609 if (DO_FALLBACK) \
610 tmesa->draw_tri( tmesa, a, b, c ); \
611 else \
612 trident_draw_triangle( tmesa, a, b, c ); \
613 } while (0)
614
615 #define QUAD( a, b, c, d ) \
616 do { \
617 if (DO_FALLBACK) { \
618 tmesa->draw_tri( tmesa, a, b, d ); \
619 tmesa->draw_tri( tmesa, b, c, d ); \
620 } else \
621 trident_draw_quad( tmesa, a, b, c, d ); \
622 } while (0)
623
624 #define LINE( v0, v1 ) \
625 do { \
626 if (DO_FALLBACK) \
627 tmesa->draw_line( tmesa, v0, v1 ); \
628 else \
629 trident_draw_line( tmesa, v0, v1 ); \
630 } while (0)
631
632 #define POINT( v0 ) \
633 do { \
634 if (DO_FALLBACK) \
635 tmesa->draw_point( tmesa, v0 ); \
636 else \
637 trident_draw_point( tmesa, v0 ); \
638 } while (0)
639
640 /***********************************************************************
641 * Build render functions from dd templates *
642 ***********************************************************************/
643
644 #define TRIDENT_OFFSET_BIT 0x01
645 #define TRIDENT_TWOSIDE_BIT 0x02
646 #define TRIDENT_UNFILLED_BIT 0x04
647 #define TRIDENT_FALLBACK_BIT 0x08
648 #define TRIDENT_MAX_TRIFUNC 0x10
649
650
651 static struct {
652 points_func points;
653 line_func line;
654 triangle_func triangle;
655 quad_func quad;
656 } rast_tab[TRIDENT_MAX_TRIFUNC];
657
658
659 #define DO_FALLBACK (IND & TRIDENT_FALLBACK_BIT)
660 #define DO_OFFSET (IND & TRIDENT_OFFSET_BIT)
661 #define DO_UNFILLED (IND & TRIDENT_UNFILLED_BIT)
662 #define DO_TWOSIDE (IND & TRIDENT_TWOSIDE_BIT)
663 #define DO_FLAT 0
664 #define DO_TRI 1
665 #define DO_QUAD 1
666 #define DO_LINE 1
667 #define DO_POINTS 1
668 #define DO_FULL_QUAD 1
669
670 #define HAVE_RGBA 1
671 #define HAVE_SPEC 1
672 #define HAVE_BACK_COLORS 0
673 #define HAVE_HW_FLATSHADE 1
674 #define VERTEX tridentVertex
675 #define TAB rast_tab
676
677 #define DEPTH_SCALE 1.0
678 #define UNFILLED_TRI unfilled_tri
679 #define UNFILLED_QUAD unfilled_quad
680 #define VERT_X(_v) _v->v.x
681 #define VERT_Y(_v) _v->v.y
682 #define VERT_Z(_v) _v->v.z
683 #define AREA_IS_CCW( a ) (a > 0)
684 #define GET_VERTEX(e) (tmesa->verts + (e<<tmesa->vertex_stride_shift))
685
686 #define TRIDENT_COLOR( dst, src ) \
687 do { \
688 dst[0] = src[2]; \
689 dst[1] = src[1]; \
690 dst[2] = src[0]; \
691 dst[3] = src[3]; \
692 } while (0)
693
694 #define TRIDENT_SPEC( dst, src ) \
695 do { \
696 dst[0] = src[2]; \
697 dst[1] = src[1]; \
698 dst[2] = src[0]; \
699 } while (0)
700
701 #define VERT_SET_RGBA( v, c ) TRIDENT_COLOR( v->ub4[coloroffset], c )
702 #define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset]
703 #define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[coloroffset]
704 #define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]
705
706 #define VERT_SET_SPEC( v, c ) if (havespec) TRIDENT_SPEC( v->ub4[5], c )
707 #define VERT_COPY_SPEC( v0, v1 ) if (havespec) COPY_3V(v0->ub4[5], v1->ub4[5])
708 #define VERT_SAVE_SPEC( idx ) if (havespec) spec[idx] = v[idx]->ui[5]
709 #define VERT_RESTORE_SPEC( idx ) if (havespec) v[idx]->ui[5] = spec[idx]
710
711 #define LOCAL_VARS(n) \
712 tridentContextPtr tmesa = TRIDENT_CONTEXT(ctx); \
713 GLuint color[n], spec[n]; \
714 GLuint coloroffset = (tmesa->vertex_size == 4 ? 3 : 4); \
715 GLboolean havespec = (tmesa->vertex_size == 4 ? 0 : 1); \
716 (void) color; (void) spec; (void) coloroffset; (void) havespec;
717 /***********************************************************************
718 * Helpers for rendering unfilled primitives *
719 ***********************************************************************/
720 #if 0
721 static const GLuint hw_prim[GL_POLYGON+1] = {
722 B_PrimType_Points,
723 B_PrimType_Lines,
724 B_PrimType_Lines,
725 B_PrimType_Lines,
726 B_PrimType_Triangles,
727 B_PrimType_Triangles,
728 B_PrimType_Triangles,
729 B_PrimType_Triangles,
730 B_PrimType_Triangles,
731 B_PrimType_Triangles
732 };
733 #endif
734
735 static void tridentResetLineStipple( GLcontext *ctx );
736 static void tridentRasterPrimitive( GLcontext *ctx, GLuint hwprim );
737 static void tridentRenderPrimitive( GLcontext *ctx, GLenum prim );
738
739 #define RASTERIZE(x) /*if (tmesa->hw_primitive != hw_prim[x]) \
740 tridentRasterPrimitive( ctx, hw_prim[x] ) */
741 #define RENDER_PRIMITIVE tmesa->render_primitive
742 #define TAG(x) x
743 #define IND TRIDENT_FALLBACK_BIT
744 #include "tnl_dd/t_dd_unfilled.h"
745 #undef IND
746
747 /***********************************************************************
748 * Generate GL render functions *
749 ***********************************************************************/
750
751 #define IND (0)
752 #define TAG(x) x
753 #include "tnl_dd/t_dd_tritmp.h"
754
755 #define IND (TRIDENT_OFFSET_BIT)
756 #define TAG(x) x##_offset
757 #include "tnl_dd/t_dd_tritmp.h"
758
759 #define IND (TRIDENT_TWOSIDE_BIT)
760 #define TAG(x) x##_twoside
761 #include "tnl_dd/t_dd_tritmp.h"
762
763 #define IND (TRIDENT_TWOSIDE_BIT|TRIDENT_OFFSET_BIT)
764 #define TAG(x) x##_twoside_offset
765 #include "tnl_dd/t_dd_tritmp.h"
766
767 #define IND (TRIDENT_UNFILLED_BIT)
768 #define TAG(x) x##_unfilled
769 #include "tnl_dd/t_dd_tritmp.h"
770
771 #define IND (TRIDENT_OFFSET_BIT|TRIDENT_UNFILLED_BIT)
772 #define TAG(x) x##_offset_unfilled
773 #include "tnl_dd/t_dd_tritmp.h"
774
775 #define IND (TRIDENT_TWOSIDE_BIT|TRIDENT_UNFILLED_BIT)
776 #define TAG(x) x##_twoside_unfilled
777 #include "tnl_dd/t_dd_tritmp.h"
778
779 #define IND (TRIDENT_TWOSIDE_BIT|TRIDENT_OFFSET_BIT|TRIDENT_UNFILLED_BIT)
780 #define TAG(x) x##_twoside_offset_unfilled
781 #include "tnl_dd/t_dd_tritmp.h"
782
783 #define IND (TRIDENT_FALLBACK_BIT)
784 #define TAG(x) x##_fallback
785 #include "tnl_dd/t_dd_tritmp.h"
786
787 #define IND (TRIDENT_OFFSET_BIT|TRIDENT_FALLBACK_BIT)
788 #define TAG(x) x##_offset_fallback
789 #include "tnl_dd/t_dd_tritmp.h"
790
791 #define IND (TRIDENT_TWOSIDE_BIT|TRIDENT_FALLBACK_BIT)
792 #define TAG(x) x##_twoside_fallback
793 #include "tnl_dd/t_dd_tritmp.h"
794
795 #define IND (TRIDENT_TWOSIDE_BIT|TRIDENT_OFFSET_BIT|TRIDENT_FALLBACK_BIT)
796 #define TAG(x) x##_twoside_offset_fallback
797 #include "tnl_dd/t_dd_tritmp.h"
798
799 #define IND (TRIDENT_UNFILLED_BIT|TRIDENT_FALLBACK_BIT)
800 #define TAG(x) x##_unfilled_fallback
801 #include "tnl_dd/t_dd_tritmp.h"
802
803 #define IND (TRIDENT_OFFSET_BIT|TRIDENT_UNFILLED_BIT|TRIDENT_FALLBACK_BIT)
804 #define TAG(x) x##_offset_unfilled_fallback
805 #include "tnl_dd/t_dd_tritmp.h"
806
807 #define IND (TRIDENT_TWOSIDE_BIT|TRIDENT_UNFILLED_BIT|TRIDENT_FALLBACK_BIT)
808 #define TAG(x) x##_twoside_unfilled_fallback
809 #include "tnl_dd/t_dd_tritmp.h"
810
811 #define IND (TRIDENT_TWOSIDE_BIT|TRIDENT_OFFSET_BIT|TRIDENT_UNFILLED_BIT|TRIDENT_FALLBACK_BIT)
812 #define TAG(x) x##_twoside_offset_unfilled_fallback
813 #include "tnl_dd/t_dd_tritmp.h"
814
815 static void init_rast_tab( void )
816 {
817 init();
818 init_offset();
819 init_twoside();
820 init_twoside_offset();
821 init_unfilled();
822 init_offset_unfilled();
823 init_twoside_unfilled();
824 init_twoside_offset_unfilled();
825 init_fallback();
826 init_offset_fallback();
827 init_twoside_fallback();
828 init_twoside_offset_fallback();
829 init_unfilled_fallback();
830 init_offset_unfilled_fallback();
831 init_twoside_unfilled_fallback();
832 init_twoside_offset_unfilled_fallback();
833 }
834
835
836 /**********************************************************************/
837 /* Render unclipped begin/end objects */
838 /**********************************************************************/
839
840 #define VERT(x) (tridentVertex *)(tridentverts + (x << shift))
841 #define RENDER_POINTS( start, count ) \
842 for ( ; start < count ; start++) \
843 trident_draw_point( tmesa, VERT(start) )
844 #define RENDER_LINE( v0, v1 ) \
845 trident_draw_line( tmesa, VERT(v0), VERT(v1) )
846 #define RENDER_TRI( v0, v1, v2 ) \
847 trident_draw_triangle( tmesa, VERT(v0), VERT(v1), VERT(v2) )
848 #define RENDER_QUAD( v0, v1, v2, v3 ) \
849 trident_draw_quad( tmesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
850 #define INIT(x) tridentRenderPrimitive( ctx, x );
851 #undef LOCAL_VARS
852 #define LOCAL_VARS \
853 tridentContextPtr tmesa = TRIDENT_CONTEXT(ctx); \
854 const GLuint shift = tmesa->vertex_stride_shift; \
855 const char *tridentverts = (char *)tmesa->verts; \
856 const GLboolean stipple = ctx->Line.StippleFlag; \
857 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
858 (void) elt;
859 #define RESET_STIPPLE if ( stipple ) tridentResetLineStipple( ctx );
860 #define RESET_OCCLUSION
861 #define PRESERVE_VB_DEFS
862 #define ELT(x) (x)
863 #define TAG(x) trident_##x##_verts
864 #include "tnl/t_vb_rendertmp.h"
865 #undef ELT
866 #undef TAG
867 #define TAG(x) trident_##x##_elts
868 #define ELT(x) elt[x]
869 #include "tnl/t_vb_rendertmp.h"
870
871 /**********************************************************************/
872 /* Render clipped primitives */
873 /**********************************************************************/
874
875 static void tridentRenderClippedPoly( GLcontext *ctx, const GLuint *elts,
876 GLuint n )
877 {
878 tridentContextPtr tmesa = TRIDENT_CONTEXT(ctx);
879 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
880 TNLcontext *tnl = TNL_CONTEXT(ctx);
881 GLuint prim = tmesa->render_primitive;
882
883 /* Render the new vertices as an unclipped polygon.
884 */
885 {
886 GLuint *tmp = VB->Elts;
887 VB->Elts = (GLuint *)elts;
888 tnl->Driver.Render.PrimTabElts[GL_POLYGON]( ctx, 0, n, PRIM_BEGIN|PRIM_END );
889 VB->Elts = tmp;
890 }
891
892 /* Restore the render primitive
893 */
894 if (prim != GL_POLYGON)
895 tnl->Driver.Render.PrimitiveNotify( ctx, prim );
896 }
897
898 static void tridentRenderClippedLine( GLcontext *ctx, GLuint ii, GLuint jj )
899 {
900 TNLcontext *tnl = TNL_CONTEXT(ctx);
901 tnl->Driver.Render.Line( ctx, ii, jj );
902 }
903
904
905 /**********************************************************************/
906 /* Choose render functions */
907 /**********************************************************************/
908
909 #define _TRIDENT_NEW_RENDER_STATE (_DD_NEW_LINE_STIPPLE | \
910 _DD_NEW_LINE_SMOOTH | \
911 _DD_NEW_POINT_SMOOTH | \
912 _DD_NEW_TRI_SMOOTH | \
913 _DD_NEW_TRI_UNFILLED | \
914 _DD_NEW_TRI_LIGHT_TWOSIDE | \
915 _DD_NEW_TRI_OFFSET) \
916
917
918 #define POINT_FALLBACK (DD_POINT_SMOOTH)
919 #define LINE_FALLBACK (DD_LINE_STIPPLE|DD_LINE_SMOOTH)
920 #define TRI_FALLBACK (DD_TRI_SMOOTH)
921 #define ANY_FALLBACK_FLAGS (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK)
922 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE|DD_TRI_OFFSET|DD_TRI_UNFILLED)
923
924
925 static void tridentChooseRenderState(GLcontext *ctx)
926 {
927 tridentContextPtr tmesa = TRIDENT_CONTEXT(ctx);
928 TNLcontext *tnl = TNL_CONTEXT(ctx);
929 GLuint flags = ctx->_TriangleCaps;
930 GLuint index = 0;
931
932 if (flags & (ANY_RASTER_FLAGS|ANY_FALLBACK_FLAGS)) {
933 tmesa->draw_point = trident_draw_point;
934 tmesa->draw_line = trident_draw_line;
935 tmesa->draw_tri = trident_draw_triangle;
936
937 if (flags & ANY_RASTER_FLAGS) {
938 if (flags & DD_TRI_LIGHT_TWOSIDE) index |= TRIDENT_TWOSIDE_BIT;
939 if (flags & DD_TRI_OFFSET) index |= TRIDENT_OFFSET_BIT;
940 if (flags & DD_TRI_UNFILLED) index |= TRIDENT_UNFILLED_BIT;
941 }
942
943 /* Hook in fallbacks for specific primitives.
944 */
945 if (flags & (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK)) {
946 if (flags & POINT_FALLBACK) tmesa->draw_point = trident_fallback_point;
947 if (flags & LINE_FALLBACK) tmesa->draw_line = trident_fallback_line;
948 if (flags & TRI_FALLBACK) tmesa->draw_tri = trident_fallback_tri;
949 index |= TRIDENT_FALLBACK_BIT;
950 }
951 }
952
953 if (tmesa->RenderIndex != index) {
954 tmesa->RenderIndex = index;
955
956 tnl->Driver.Render.Points = rast_tab[index].points;
957 tnl->Driver.Render.Line = rast_tab[index].line;
958 tnl->Driver.Render.Triangle = rast_tab[index].triangle;
959 tnl->Driver.Render.Quad = rast_tab[index].quad;
960
961 if (tmesa->RenderIndex == 0) {
962 tnl->Driver.Render.PrimTabVerts = trident_render_tab_verts;
963 tnl->Driver.Render.PrimTabElts = trident_render_tab_elts;
964 } else {
965 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
966 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
967 }
968 tnl->Driver.Render.ClippedLine = tridentRenderClippedLine;
969 tnl->Driver.Render.ClippedPolygon = tridentRenderClippedPoly;
970 }
971 }
972
973
974 /**********************************************************************/
975 /* High level hooks for t_vb_render.c */
976 /**********************************************************************/
977
978
979
980 /* Determine the rasterized primitive when not drawing unfilled
981 * polygons.
982 *
983 * Used only for the default render stage which always decomposes
984 * primitives to trianges/lines/points. For the accelerated stage,
985 * which renders strips as strips, the equivalent calculations are
986 * performed in tridentrender.c.
987 */
988
989 static void tridentRasterPrimitive( GLcontext *ctx, GLuint hwprim )
990 {
991 tridentContextPtr tmesa = TRIDENT_CONTEXT(ctx);
992 if (tmesa->hw_primitive != hwprim)
993 tmesa->hw_primitive = hwprim;
994 }
995
996 static void tridentRenderPrimitive( GLcontext *ctx, GLenum prim )
997 {
998 tridentContextPtr tmesa = TRIDENT_CONTEXT(ctx);
999 tmesa->render_primitive = prim;
1000 }
1001
1002 static void tridentRunPipeline( GLcontext *ctx )
1003 {
1004 tridentContextPtr tmesa = TRIDENT_CONTEXT(ctx);
1005
1006 if ( tmesa->new_state )
1007 tridentDDUpdateHWState( ctx );
1008
1009 if (tmesa->new_gl_state) {
1010 #if 0
1011 if (tmesa->new_gl_state & _NEW_TEXTURE)
1012 tridentUpdateTextureState( ctx );
1013 #endif
1014
1015 if (!tmesa->Fallback) {
1016 if (tmesa->new_gl_state & _TRIDENT_NEW_VERTEX)
1017 tridentChooseVertexState( ctx );
1018
1019 if (tmesa->new_gl_state & _TRIDENT_NEW_RENDER_STATE)
1020 tridentChooseRenderState( ctx );
1021 }
1022
1023 tmesa->new_gl_state = 0;
1024 }
1025
1026 _tnl_run_pipeline( ctx );
1027 }
1028
1029 static void tridentRenderStart( GLcontext *ctx )
1030 {
1031 /* Check for projective texturing. Make sure all texcoord
1032 * pointers point to something. (fix in mesa?)
1033 */
1034 tridentCheckTexSizes( ctx );
1035 }
1036
1037 static void tridentRenderFinish( GLcontext *ctx )
1038 {
1039 if (0)
1040 _swrast_flush( ctx ); /* never needed */
1041 }
1042
1043 static void tridentResetLineStipple( GLcontext *ctx )
1044 {
1045 tridentContextPtr tmesa = TRIDENT_CONTEXT(ctx);
1046
1047 /* Reset the hardware stipple counter.
1048 */
1049 }
1050
1051
1052 /**********************************************************************/
1053 /* Transition to/from hardware rasterization. */
1054 /**********************************************************************/
1055
1056
1057 void tridentFallback( tridentContextPtr tmesa, GLuint bit, GLboolean mode )
1058 {
1059 GLcontext *ctx = tmesa->glCtx;
1060 TNLcontext *tnl = TNL_CONTEXT(ctx);
1061 GLuint oldfallback = tmesa->Fallback;
1062
1063 _tnl_need_projected_coords( ctx, GL_FALSE );
1064
1065 if (mode) {
1066 tmesa->Fallback |= bit;
1067 if (oldfallback == 0) {
1068 _swsetup_Wakeup( ctx );
1069 tmesa->RenderIndex = ~0;
1070 }
1071 }
1072 else {
1073 tmesa->Fallback &= ~bit;
1074 if (oldfallback == bit) {
1075 _swrast_flush( ctx );
1076 tnl->Driver.Render.Start = tridentRenderStart;
1077 tnl->Driver.Render.PrimitiveNotify = tridentRenderPrimitive;
1078 tnl->Driver.Render.Finish = tridentRenderFinish;
1079 tnl->Driver.Render.BuildVertices = tridentBuildVertices;
1080 tnl->Driver.Render.ResetLineStipple = tridentResetLineStipple;
1081 tmesa->new_gl_state |= (_TRIDENT_NEW_RENDER_STATE|
1082 _TRIDENT_NEW_VERTEX);
1083 }
1084 }
1085 }
1086
1087
1088 /**********************************************************************/
1089 /* Initialization. */
1090 /**********************************************************************/
1091
1092
1093 void tridentDDInitTriFuncs( GLcontext *ctx )
1094 {
1095 tridentContextPtr tmesa = TRIDENT_CONTEXT(ctx);
1096 TNLcontext *tnl = TNL_CONTEXT(ctx);
1097 static int firsttime = 1;
1098
1099 if (firsttime) {
1100 init_rast_tab();
1101 firsttime = 0;
1102 }
1103
1104 tmesa->RenderIndex = ~0;
1105
1106 tnl->Driver.RunPipeline = tridentRunPipeline;
1107 tnl->Driver.Render.Start = tridentRenderStart;
1108 tnl->Driver.Render.Finish = tridentRenderFinish;
1109 tnl->Driver.Render.PrimitiveNotify = tridentRenderPrimitive;
1110 tnl->Driver.Render.ResetLineStipple = tridentResetLineStipple;
1111 tnl->Driver.Render.BuildVertices = tridentBuildVertices;
1112 }