2 * Copyright 2002 by Alan Hourihane, Sychdyn, North Wales, UK.
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.
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.
22 * Authors: Alan Hourihane, <alanh@fairlite.demon.co.uk>
24 * Trident CyberBladeXP driver.
28 #include "trident_context.h"
29 #include "trident_lock.h"
31 #include "tnl/t_context.h"
32 #include "tnl/t_pipeline.h"
33 #include "swrast/swrast.h"
42 RegData initRegData
[]={
63 {0x2C94 , 0xFFFFFFFF},
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},*/
262 int initRegDataNum
=sizeof(initRegData
)/sizeof(RegData
);
267 } dmaBufRec
, *dmaBuf
;
269 void Init3D( tridentContextPtr tmesa
)
271 unsigned char *MMIO
= tmesa
->tridentScreen
->mmio
.map
;
274 for(i
=0;i
<initRegDataNum
;++i
)
275 MMIO_OUT32(MMIO
, initRegData
[i
].addr
, initRegData
[i
].data
);
278 int DrawTriangle( tridentContextPtr tmesa
)
280 volatile unsigned char *MMIO
= tmesa
->tridentScreen
->mmio
.map
;
283 printf("DRAW TRI\n");
286 printf("ENGINE STATUS 0x%x\n",MMIO_IN32(MMIO
, 0x2800));
287 MMIO_OUT32(MMIO
, 0x002800, 0x00000000 );
289 MMIO_OUT32(MMIO
, 0x002368 , MMIO_IN32(MMIO
,0x002368)|1 );
292 MMIO_OUT32(MMIO
, 0x002C00 , 0x00000014 );
294 MMIO_OUT32(MMIO
, 0x002C04 , 0x0A8004C0 );
296 MMIO_OUT32(MMIO
, 0x002C04 , 0x0A8000C0 );
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 );
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 );
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 );
338 MMIO_OUT32(MMIO
, 0x002814, 0x00000000 );
340 MMIO_OUT32(MMIO
, 0x002818 , 0x00036C20 );
342 MMIO_OUT32(MMIO
, 0x002818 , 0x00036020 );
344 MMIO_OUT32(MMIO
, 0x00281C , 0x00098081 );
346 printf("first TRI\n");
348 MMIO_OUT32(MMIO
, 0x002820 , clr
.i
);
350 MMIO_OUT32(MMIO
, 0x002824 , clr
.i
);
352 MMIO_OUT32(MMIO
, 0x002828 , clr
.i
);
353 MMIO_OUT32(MMIO
, 0x00282C , 0x00FF00 );
356 MMIO_OUT32(MMIO
, 0x002830 , clr
.i
);
358 MMIO_OUT32(MMIO
, 0x002834 , clr
.i
);
362 MMIO_OUT32(MMIO
, 0x002820 , clr
.i
);
364 MMIO_OUT32(MMIO
, 0x002824 , clr
.i
);
366 MMIO_OUT32(MMIO
, 0x002828 , clr
.i
);
367 MMIO_OUT32(MMIO
, 0x00282C , 0xFF0000 );
370 MMIO_OUT32(MMIO
, 0x002830 , clr
.i
);
372 MMIO_OUT32(MMIO
, 0x002834 , clr
.i
);
376 printf("0x%x\n",clr
.i
);
377 MMIO_OUT32(MMIO
, 0x002820 , clr
.i
);
379 MMIO_OUT32(MMIO
, 0x002824 , clr
.i
);
381 MMIO_OUT32(MMIO
, 0x002828 , clr
.i
);
382 MMIO_OUT32(MMIO
, 0x00282C , 0xFF );
385 MMIO_OUT32(MMIO
, 0x002830 , clr
.i
);
387 MMIO_OUT32(MMIO
, 0x002834 , clr
.i
);
391 MMIO_OUT32(MMIO
, 0x00281C , 0x00093980 );
393 MMIO_OUT32(MMIO
, 0x002820 , clr
.i
);
395 MMIO_OUT32(MMIO
, 0x002824 , clr
.i
);
397 MMIO_OUT32(MMIO
, 0x002828 , clr
.i
);
398 MMIO_OUT32(MMIO
, 0x00282C , 0x00FF00 );
401 MMIO_OUT32(MMIO
, 0x002830 , clr
.i
);
403 MMIO_OUT32(MMIO
, 0x002834 , clr
.i
);
407 MMIO_OUT32(MMIO
, 0x002368 , MMIO_IN32(MMIO
,0x002368)&0xfffffffe );
415 static INLINE
void trident_draw_point(tridentContextPtr tmesa
,
416 const tridentVertex
*v0
)
418 unsigned char *MMIO
= tmesa
->tridentScreen
->mmio
.map
;
421 static INLINE
void trident_draw_line( tridentContextPtr tmesa
,
422 const tridentVertex
*v0
,
423 const tridentVertex
*v1
)
425 unsigned char *MMIO
= tmesa
->tridentScreen
->mmio
.map
;
428 static INLINE
void trident_draw_triangle( tridentContextPtr tmesa
,
429 const tridentVertex
*v0
,
430 const tridentVertex
*v1
,
431 const tridentVertex
*v2
)
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
)
441 GLuint vertsize
= tmesa
->vertex_size
;
442 GLint coloridx
= (vertsize
> 4) ? 4 : 3;
443 unsigned char *MMIO
= tmesa
->tridentScreen
->mmio
.map
;
445 float *ftmp
= (float *)(&clr
);
448 tridentUploadHwStateLocked( tmesa
);
463 LOCK_HARDWARE( tmesa
);
465 MMIO_OUT32(MMIO
, 0x002C00 , 0x00000010 );
466 MMIO_OUT32(MMIO
, 0x002C04 , 0x029C00C0 );
469 MMIO_OUT32(MMIO
, 0x002C24 , 0x00100000 /*| (tmesa->tridentScreen->depthOffset)*/ );
470 MMIO_OUT32(MMIO
, 0x002C28 , 0xE0000000 | (tmesa
->tridentScreen
->depthPitch
* 4) );
473 MMIO_OUT32(MMIO
, 0x002C50 , 0x00000000 | (tmesa
->drawOffset
) );
474 MMIO_OUT32(MMIO
, 0x002C54 , 0x0C320000 | (tmesa
->drawPitch
* 4) );
477 MMIO_OUT32(MMIO
, 0x002C80 , 0x20008000 | tmesa
->tridentScreen
->height
);
478 MMIO_OUT32(MMIO
, 0x002C84 , 0x20000000 | tmesa
->tridentScreen
->width
);
481 MMIO_OUT32(MMIO
, 0x002C94 , 0xFFFFFFFF );
484 MMIO_OUT32(MMIO
, 0x002818 , 0x0003A020 );
485 MMIO_OUT32(MMIO
, 0x00281C , 0x00098021 );
488 MMIO_OUT32(MMIO
, 0x002820 , clr
);
490 MMIO_OUT32(MMIO
, 0x002824 , clr
);
492 MMIO_OUT32(MMIO
, 0x002828 , clr
);
495 MMIO_OUT32(MMIO
, 0x00282C , clr
);
497 MMIO_OUT32(MMIO
, 0x00282C , v0
->ui
[coloridx
] );
500 MMIO_OUT32(MMIO
, 0x002820 , clr
);
502 MMIO_OUT32(MMIO
, 0x002824 , clr
);
504 MMIO_OUT32(MMIO
, 0x002828 , clr
);
507 MMIO_OUT32(MMIO
, 0x00282C , clr
);
509 MMIO_OUT32(MMIO
, 0x00282C , v1
->ui
[coloridx
] );
512 MMIO_OUT32(MMIO
, 0x002820 , clr
);
514 MMIO_OUT32(MMIO
, 0x002824 , clr
);
516 MMIO_OUT32(MMIO
, 0x002828 , clr
);
519 MMIO_OUT32(MMIO
, 0x00282C , clr
);
521 MMIO_OUT32(MMIO
, 0x00282C , v2
->ui
[coloridx
] );
523 MMIO_OUT32(MMIO
, 0x00281C , 0x00093020 );
525 MMIO_OUT32(MMIO
, 0x002820 , clr
);
527 MMIO_OUT32(MMIO
, 0x002824 , clr
);
529 MMIO_OUT32(MMIO
, 0x002828 , clr
);
532 MMIO_OUT32(MMIO
, 0x00282C , clr
);
534 MMIO_OUT32(MMIO
, 0x00282C , v3
->ui
[coloridx
] );
539 UNLOCK_HARDWARE( tmesa
);
541 /***********************************************************************
542 * Rasterization fallback helpers *
543 ***********************************************************************/
546 /* This code is hit only when a mix of accelerated and unaccelerated
547 * primitives are being drawn, and only for the unaccelerated
551 trident_fallback_quad( tridentContextPtr tmesa
,
552 const tridentVertex
*v0
,
553 const tridentVertex
*v1
,
554 const tridentVertex
*v2
,
555 const tridentVertex
*v3
)
557 GLcontext
*ctx
= tmesa
->glCtx
;
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] );
567 trident_fallback_tri( tridentContextPtr tmesa
,
568 const tridentVertex
*v0
,
569 const tridentVertex
*v1
,
570 const tridentVertex
*v2
)
572 GLcontext
*ctx
= tmesa
->glCtx
;
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] );
581 trident_fallback_line( tridentContextPtr tmesa
,
582 const tridentVertex
*v0
,
583 const tridentVertex
*v1
)
585 GLcontext
*ctx
= tmesa
->glCtx
;
587 trident_translate_vertex( ctx
, v0
, &v
[0] );
588 trident_translate_vertex( ctx
, v1
, &v
[1] );
589 _swrast_Line( ctx
, &v
[0], &v
[1] );
594 trident_fallback_point( tridentContextPtr tmesa
,
595 const tridentVertex
*v0
)
597 GLcontext
*ctx
= tmesa
->glCtx
;
599 trident_translate_vertex( ctx
, v0
, &v
[0] );
600 _swrast_Point( ctx
, &v
[0] );
603 /***********************************************************************
604 * Macros for t_dd_tritmp.h to draw basic primitives *
605 ***********************************************************************/
607 #define TRI( a, b, c ) \
610 tmesa->draw_tri( tmesa, a, b, c ); \
612 trident_draw_triangle( tmesa, a, b, c ); \
615 #define QUAD( a, b, c, d ) \
618 tmesa->draw_tri( tmesa, a, b, d ); \
619 tmesa->draw_tri( tmesa, b, c, d ); \
621 trident_draw_quad( tmesa, a, b, c, d ); \
624 #define LINE( v0, v1 ) \
627 tmesa->draw_line( tmesa, v0, v1 ); \
629 trident_draw_line( tmesa, v0, v1 ); \
632 #define POINT( v0 ) \
635 tmesa->draw_point( tmesa, v0 ); \
637 trident_draw_point( tmesa, v0 ); \
640 /***********************************************************************
641 * Build render functions from dd templates *
642 ***********************************************************************/
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
654 triangle_func triangle
;
656 } rast_tab
[TRIDENT_MAX_TRIFUNC
];
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)
668 #define DO_FULL_QUAD 1
672 #define HAVE_BACK_COLORS 0
673 #define HAVE_HW_FLATSHADE 1
674 #define VERTEX tridentVertex
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))
686 #define TRIDENT_COLOR( dst, src ) \
694 #define TRIDENT_SPEC( dst, src ) \
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]
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]
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 ***********************************************************************/
721 static const GLuint hw_prim
[GL_POLYGON
+1] = {
726 B_PrimType_Triangles
,
727 B_PrimType_Triangles
,
728 B_PrimType_Triangles
,
729 B_PrimType_Triangles
,
730 B_PrimType_Triangles
,
735 static void tridentResetLineStipple( GLcontext
*ctx
);
736 static void tridentRasterPrimitive( GLcontext
*ctx
, GLuint hwprim
);
737 static void tridentRenderPrimitive( GLcontext
*ctx
, GLenum prim
);
739 #define RASTERIZE(x) /*if (tmesa->hw_primitive != hw_prim[x]) \
740 tridentRasterPrimitive( ctx, hw_prim[x] ) */
741 #define RENDER_PRIMITIVE tmesa->render_primitive
743 #define IND TRIDENT_FALLBACK_BIT
744 #include "tnl_dd/t_dd_unfilled.h"
747 /***********************************************************************
748 * Generate GL render functions *
749 ***********************************************************************/
753 #include "tnl_dd/t_dd_tritmp.h"
755 #define IND (TRIDENT_OFFSET_BIT)
756 #define TAG(x) x##_offset
757 #include "tnl_dd/t_dd_tritmp.h"
759 #define IND (TRIDENT_TWOSIDE_BIT)
760 #define TAG(x) x##_twoside
761 #include "tnl_dd/t_dd_tritmp.h"
763 #define IND (TRIDENT_TWOSIDE_BIT|TRIDENT_OFFSET_BIT)
764 #define TAG(x) x##_twoside_offset
765 #include "tnl_dd/t_dd_tritmp.h"
767 #define IND (TRIDENT_UNFILLED_BIT)
768 #define TAG(x) x##_unfilled
769 #include "tnl_dd/t_dd_tritmp.h"
771 #define IND (TRIDENT_OFFSET_BIT|TRIDENT_UNFILLED_BIT)
772 #define TAG(x) x##_offset_unfilled
773 #include "tnl_dd/t_dd_tritmp.h"
775 #define IND (TRIDENT_TWOSIDE_BIT|TRIDENT_UNFILLED_BIT)
776 #define TAG(x) x##_twoside_unfilled
777 #include "tnl_dd/t_dd_tritmp.h"
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"
783 #define IND (TRIDENT_FALLBACK_BIT)
784 #define TAG(x) x##_fallback
785 #include "tnl_dd/t_dd_tritmp.h"
787 #define IND (TRIDENT_OFFSET_BIT|TRIDENT_FALLBACK_BIT)
788 #define TAG(x) x##_offset_fallback
789 #include "tnl_dd/t_dd_tritmp.h"
791 #define IND (TRIDENT_TWOSIDE_BIT|TRIDENT_FALLBACK_BIT)
792 #define TAG(x) x##_twoside_fallback
793 #include "tnl_dd/t_dd_tritmp.h"
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"
799 #define IND (TRIDENT_UNFILLED_BIT|TRIDENT_FALLBACK_BIT)
800 #define TAG(x) x##_unfilled_fallback
801 #include "tnl_dd/t_dd_tritmp.h"
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"
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"
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"
815 static void init_rast_tab( void )
820 init_twoside_offset();
822 init_offset_unfilled();
823 init_twoside_unfilled();
824 init_twoside_offset_unfilled();
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();
836 /**********************************************************************/
837 /* Render unclipped begin/end objects */
838 /**********************************************************************/
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 );
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; \
859 #define RESET_STIPPLE if ( stipple ) tridentResetLineStipple( ctx );
860 #define RESET_OCCLUSION
861 #define PRESERVE_VB_DEFS
863 #define TAG(x) trident_##x##_verts
864 #include "tnl/t_vb_rendertmp.h"
867 #define TAG(x) trident_##x##_elts
868 #define ELT(x) elt[x]
869 #include "tnl/t_vb_rendertmp.h"
871 /**********************************************************************/
872 /* Render clipped primitives */
873 /**********************************************************************/
875 static void tridentRenderClippedPoly( GLcontext
*ctx
, const GLuint
*elts
,
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
;
883 /* Render the new vertices as an unclipped polygon.
886 GLuint
*tmp
= VB
->Elts
;
887 VB
->Elts
= (GLuint
*)elts
;
888 tnl
->Driver
.Render
.PrimTabElts
[GL_POLYGON
]( ctx
, 0, n
, PRIM_BEGIN
|PRIM_END
);
892 /* Restore the render primitive
894 if (prim
!= GL_POLYGON
)
895 tnl
->Driver
.Render
.PrimitiveNotify( ctx
, prim
);
898 static void tridentRenderClippedLine( GLcontext
*ctx
, GLuint ii
, GLuint jj
)
900 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
901 tnl
->Driver
.Render
.Line( ctx
, ii
, jj
);
905 /**********************************************************************/
906 /* Choose render functions */
907 /**********************************************************************/
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) \
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)
925 static void tridentChooseRenderState(GLcontext
*ctx
)
927 tridentContextPtr tmesa
= TRIDENT_CONTEXT(ctx
);
928 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
929 GLuint flags
= ctx
->_TriangleCaps
;
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
;
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
;
943 /* Hook in fallbacks for specific primitives.
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
;
953 if (tmesa
->RenderIndex
!= index
) {
954 tmesa
->RenderIndex
= index
;
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
;
961 if (tmesa
->RenderIndex
== 0) {
962 tnl
->Driver
.Render
.PrimTabVerts
= trident_render_tab_verts
;
963 tnl
->Driver
.Render
.PrimTabElts
= trident_render_tab_elts
;
965 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
966 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
968 tnl
->Driver
.Render
.ClippedLine
= tridentRenderClippedLine
;
969 tnl
->Driver
.Render
.ClippedPolygon
= tridentRenderClippedPoly
;
974 /**********************************************************************/
975 /* High level hooks for t_vb_render.c */
976 /**********************************************************************/
980 /* Determine the rasterized primitive when not drawing unfilled
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.
989 static void tridentRasterPrimitive( GLcontext
*ctx
, GLuint hwprim
)
991 tridentContextPtr tmesa
= TRIDENT_CONTEXT(ctx
);
992 if (tmesa
->hw_primitive
!= hwprim
)
993 tmesa
->hw_primitive
= hwprim
;
996 static void tridentRenderPrimitive( GLcontext
*ctx
, GLenum prim
)
998 tridentContextPtr tmesa
= TRIDENT_CONTEXT(ctx
);
999 tmesa
->render_primitive
= prim
;
1002 static void tridentRunPipeline( GLcontext
*ctx
)
1004 tridentContextPtr tmesa
= TRIDENT_CONTEXT(ctx
);
1006 if ( tmesa
->new_state
)
1007 tridentDDUpdateHWState( ctx
);
1009 if (tmesa
->new_gl_state
) {
1011 if (tmesa
->new_gl_state
& _NEW_TEXTURE
)
1012 tridentUpdateTextureState( ctx
);
1015 if (!tmesa
->Fallback
) {
1016 if (tmesa
->new_gl_state
& _TRIDENT_NEW_VERTEX
)
1017 tridentChooseVertexState( ctx
);
1019 if (tmesa
->new_gl_state
& _TRIDENT_NEW_RENDER_STATE
)
1020 tridentChooseRenderState( ctx
);
1023 tmesa
->new_gl_state
= 0;
1026 _tnl_run_pipeline( ctx
);
1029 static void tridentRenderStart( GLcontext
*ctx
)
1031 /* Check for projective texturing. Make sure all texcoord
1032 * pointers point to something. (fix in mesa?)
1034 tridentCheckTexSizes( ctx
);
1037 static void tridentRenderFinish( GLcontext
*ctx
)
1040 _swrast_flush( ctx
); /* never needed */
1043 static void tridentResetLineStipple( GLcontext
*ctx
)
1045 tridentContextPtr tmesa
= TRIDENT_CONTEXT(ctx
);
1047 /* Reset the hardware stipple counter.
1052 /**********************************************************************/
1053 /* Transition to/from hardware rasterization. */
1054 /**********************************************************************/
1057 void tridentFallback( tridentContextPtr tmesa
, GLuint bit
, GLboolean mode
)
1059 GLcontext
*ctx
= tmesa
->glCtx
;
1060 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1061 GLuint oldfallback
= tmesa
->Fallback
;
1063 _tnl_need_projected_coords( ctx
, GL_FALSE
);
1066 tmesa
->Fallback
|= bit
;
1067 if (oldfallback
== 0) {
1068 _swsetup_Wakeup( ctx
);
1069 tmesa
->RenderIndex
= ~0;
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
);
1088 /**********************************************************************/
1089 /* Initialization. */
1090 /**********************************************************************/
1093 void tridentDDInitTriFuncs( GLcontext
*ctx
)
1095 tridentContextPtr tmesa
= TRIDENT_CONTEXT(ctx
);
1096 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1097 static int firsttime
= 1;
1104 tmesa
->RenderIndex
= ~0;
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
;