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