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"
34 #include "swrast_setup/swrast_setup.h"
43 RegData initRegData
[]={
64 {0x2C94 , 0xFFFFFFFF},
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},*/
263 int initRegDataNum
=sizeof(initRegData
)/sizeof(RegData
);
268 } dmaBufRec
, *dmaBuf
;
270 void Init3D( tridentContextPtr tmesa
)
272 unsigned char *MMIO
= tmesa
->tridentScreen
->mmio
.map
;
275 for(i
=0;i
<initRegDataNum
;++i
)
276 MMIO_OUT32(MMIO
, initRegData
[i
].addr
, initRegData
[i
].data
);
279 int DrawTriangle( tridentContextPtr tmesa
)
281 unsigned char *MMIO
= tmesa
->tridentScreen
->mmio
.map
;
284 printf("DRAW TRI\n");
287 printf("ENGINE STATUS 0x%x\n",MMIO_IN32(MMIO
, 0x2800));
288 MMIO_OUT32(MMIO
, 0x002800, 0x00000000 );
290 MMIO_OUT32(MMIO
, 0x002368 , MMIO_IN32(MMIO
,0x002368)|1 );
293 MMIO_OUT32(MMIO
, 0x002C00 , 0x00000014 );
295 MMIO_OUT32(MMIO
, 0x002C04 , 0x0A8004C0 );
297 MMIO_OUT32(MMIO
, 0x002C04 , 0x0A8000C0 );
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 );
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 );
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 );
339 MMIO_OUT32(MMIO
, 0x002814, 0x00000000 );
341 MMIO_OUT32(MMIO
, 0x002818 , 0x00036C20 );
343 MMIO_OUT32(MMIO
, 0x002818 , 0x00036020 );
345 MMIO_OUT32(MMIO
, 0x00281C , 0x00098081 );
347 printf("first TRI\n");
349 MMIO_OUT32(MMIO
, 0x002820 , clr
.i
);
351 MMIO_OUT32(MMIO
, 0x002824 , clr
.i
);
353 MMIO_OUT32(MMIO
, 0x002828 , clr
.i
);
354 MMIO_OUT32(MMIO
, 0x00282C , 0x00FF00 );
357 MMIO_OUT32(MMIO
, 0x002830 , clr
.i
);
359 MMIO_OUT32(MMIO
, 0x002834 , clr
.i
);
363 MMIO_OUT32(MMIO
, 0x002820 , clr
.i
);
365 MMIO_OUT32(MMIO
, 0x002824 , clr
.i
);
367 MMIO_OUT32(MMIO
, 0x002828 , clr
.i
);
368 MMIO_OUT32(MMIO
, 0x00282C , 0xFF0000 );
371 MMIO_OUT32(MMIO
, 0x002830 , clr
.i
);
373 MMIO_OUT32(MMIO
, 0x002834 , clr
.i
);
377 printf("0x%x\n",clr
.i
);
378 MMIO_OUT32(MMIO
, 0x002820 , clr
.i
);
380 MMIO_OUT32(MMIO
, 0x002824 , clr
.i
);
382 MMIO_OUT32(MMIO
, 0x002828 , clr
.i
);
383 MMIO_OUT32(MMIO
, 0x00282C , 0xFF );
386 MMIO_OUT32(MMIO
, 0x002830 , clr
.i
);
388 MMIO_OUT32(MMIO
, 0x002834 , clr
.i
);
392 MMIO_OUT32(MMIO
, 0x00281C , 0x00093980 );
394 MMIO_OUT32(MMIO
, 0x002820 , clr
.i
);
396 MMIO_OUT32(MMIO
, 0x002824 , clr
.i
);
398 MMIO_OUT32(MMIO
, 0x002828 , clr
.i
);
399 MMIO_OUT32(MMIO
, 0x00282C , 0x00FF00 );
402 MMIO_OUT32(MMIO
, 0x002830 , clr
.i
);
404 MMIO_OUT32(MMIO
, 0x002834 , clr
.i
);
408 MMIO_OUT32(MMIO
, 0x002368 , MMIO_IN32(MMIO
,0x002368)&0xfffffffe );
416 static INLINE
void trident_draw_point(tridentContextPtr tmesa
,
417 const tridentVertex
*v0
)
419 unsigned char *MMIO
= tmesa
->tridentScreen
->mmio
.map
;
423 static INLINE
void trident_draw_line( tridentContextPtr tmesa
,
424 const tridentVertex
*v0
,
425 const tridentVertex
*v1
)
427 unsigned char *MMIO
= tmesa
->tridentScreen
->mmio
.map
;
431 static INLINE
void trident_draw_triangle( tridentContextPtr tmesa
,
432 const tridentVertex
*v0
,
433 const tridentVertex
*v1
,
434 const tridentVertex
*v2
)
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
)
444 GLuint vertsize
= tmesa
->vertex_size
;
445 GLint coloridx
= (vertsize
> 4) ? 4 : 3;
446 unsigned char *MMIO
= tmesa
->tridentScreen
->mmio
.map
;
448 float *ftmp
= (float *)(&clr
);
451 tridentUploadHwStateLocked( tmesa
);
466 LOCK_HARDWARE( tmesa
);
468 MMIO_OUT32(MMIO
, 0x002C00 , 0x00000010 );
469 MMIO_OUT32(MMIO
, 0x002C04 , 0x029C00C0 );
472 MMIO_OUT32(MMIO
, 0x002C24 , 0x00100000 /*| (tmesa->tridentScreen->depthOffset)*/ );
473 MMIO_OUT32(MMIO
, 0x002C28 , 0xE0000000 | (tmesa
->tridentScreen
->depthPitch
* 4) );
476 MMIO_OUT32(MMIO
, 0x002C50 , 0x00000000 | (tmesa
->drawOffset
) );
477 MMIO_OUT32(MMIO
, 0x002C54 , 0x0C320000 | (tmesa
->drawPitch
* 4) );
480 MMIO_OUT32(MMIO
, 0x002C80 , 0x20008000 | tmesa
->tridentScreen
->height
);
481 MMIO_OUT32(MMIO
, 0x002C84 , 0x20000000 | tmesa
->tridentScreen
->width
);
484 MMIO_OUT32(MMIO
, 0x002C94 , 0xFFFFFFFF );
487 MMIO_OUT32(MMIO
, 0x002818 , 0x0003A020 );
488 MMIO_OUT32(MMIO
, 0x00281C , 0x00098021 );
491 MMIO_OUT32(MMIO
, 0x002820 , clr
);
493 MMIO_OUT32(MMIO
, 0x002824 , clr
);
495 MMIO_OUT32(MMIO
, 0x002828 , clr
);
498 MMIO_OUT32(MMIO
, 0x00282C , clr
);
500 MMIO_OUT32(MMIO
, 0x00282C , v0
->ui
[coloridx
] );
503 MMIO_OUT32(MMIO
, 0x002820 , clr
);
505 MMIO_OUT32(MMIO
, 0x002824 , clr
);
507 MMIO_OUT32(MMIO
, 0x002828 , clr
);
510 MMIO_OUT32(MMIO
, 0x00282C , clr
);
512 MMIO_OUT32(MMIO
, 0x00282C , v1
->ui
[coloridx
] );
515 MMIO_OUT32(MMIO
, 0x002820 , clr
);
517 MMIO_OUT32(MMIO
, 0x002824 , clr
);
519 MMIO_OUT32(MMIO
, 0x002828 , clr
);
522 MMIO_OUT32(MMIO
, 0x00282C , clr
);
524 MMIO_OUT32(MMIO
, 0x00282C , v2
->ui
[coloridx
] );
526 MMIO_OUT32(MMIO
, 0x00281C , 0x00093020 );
528 MMIO_OUT32(MMIO
, 0x002820 , clr
);
530 MMIO_OUT32(MMIO
, 0x002824 , clr
);
532 MMIO_OUT32(MMIO
, 0x002828 , clr
);
535 MMIO_OUT32(MMIO
, 0x00282C , clr
);
537 MMIO_OUT32(MMIO
, 0x00282C , v3
->ui
[coloridx
] );
542 UNLOCK_HARDWARE( tmesa
);
544 /***********************************************************************
545 * Rasterization fallback helpers *
546 ***********************************************************************/
549 /* This code is hit only when a mix of accelerated and unaccelerated
550 * primitives are being drawn, and only for the unaccelerated
555 trident_fallback_quad( tridentContextPtr tmesa
,
556 const tridentVertex
*v0
,
557 const tridentVertex
*v1
,
558 const tridentVertex
*v2
,
559 const tridentVertex
*v3
)
561 GLcontext
*ctx
= tmesa
->glCtx
;
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] );
571 /* XXX hack to get the prototype defined in time... */
572 void trident_translate_vertex(GLcontext
*ctx
, const tridentVertex
*src
,
576 trident_fallback_tri( tridentContextPtr tmesa
,
577 const tridentVertex
*v0
,
578 const tridentVertex
*v1
,
579 const tridentVertex
*v2
)
581 GLcontext
*ctx
= tmesa
->glCtx
;
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] );
590 trident_fallback_line( tridentContextPtr tmesa
,
591 const tridentVertex
*v0
,
592 const tridentVertex
*v1
)
594 GLcontext
*ctx
= tmesa
->glCtx
;
596 trident_translate_vertex( ctx
, v0
, &v
[0] );
597 trident_translate_vertex( ctx
, v1
, &v
[1] );
598 _swrast_Line( ctx
, &v
[0], &v
[1] );
603 trident_fallback_point( tridentContextPtr tmesa
,
604 const tridentVertex
*v0
)
606 GLcontext
*ctx
= tmesa
->glCtx
;
608 trident_translate_vertex( ctx
, v0
, &v
[0] );
609 _swrast_Point( ctx
, &v
[0] );
612 /***********************************************************************
613 * Macros for t_dd_tritmp.h to draw basic primitives *
614 ***********************************************************************/
616 #define TRI( a, b, c ) \
619 tmesa->draw_tri( tmesa, a, b, c ); \
621 trident_draw_triangle( tmesa, a, b, c ); \
624 #define QUAD( a, b, c, d ) \
627 tmesa->draw_tri( tmesa, a, b, d ); \
628 tmesa->draw_tri( tmesa, b, c, d ); \
630 trident_draw_quad( tmesa, a, b, c, d ); \
633 #define LINE( v0, v1 ) \
636 tmesa->draw_line( tmesa, v0, v1 ); \
638 trident_draw_line( tmesa, v0, v1 ); \
641 #define POINT( v0 ) \
644 tmesa->draw_point( tmesa, v0 ); \
646 trident_draw_point( tmesa, v0 ); \
649 /***********************************************************************
650 * Build render functions from dd templates *
651 ***********************************************************************/
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
661 tnl_points_func points
;
663 tnl_triangle_func triangle
;
665 } rast_tab
[TRIDENT_MAX_TRIFUNC
];
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)
677 #define DO_FULL_QUAD 1
681 #define HAVE_BACK_COLORS 0
682 #define HAVE_HW_FLATSHADE 1
683 #define VERTEX tridentVertex
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))
695 #define TRIDENT_COLOR( dst, src ) \
703 #define TRIDENT_SPEC( dst, src ) \
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]
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]
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 ***********************************************************************/
730 static const GLuint hw_prim
[GL_POLYGON
+1] = {
735 B_PrimType_Triangles
,
736 B_PrimType_Triangles
,
737 B_PrimType_Triangles
,
738 B_PrimType_Triangles
,
739 B_PrimType_Triangles
,
744 static void tridentResetLineStipple( GLcontext
*ctx
);
746 static void tridentRasterPrimitive( GLcontext
*ctx
, GLuint hwprim
);
748 static void tridentRenderPrimitive( GLcontext
*ctx
, GLenum prim
);
750 #define RASTERIZE(x) /*if (tmesa->hw_primitive != hw_prim[x]) \
751 tridentRasterPrimitive( ctx, hw_prim[x] ) */
752 #define RENDER_PRIMITIVE tmesa->render_primitive
754 #define IND TRIDENT_FALLBACK_BIT
755 #include "tnl_dd/t_dd_unfilled.h"
758 /***********************************************************************
759 * Generate GL render functions *
760 ***********************************************************************/
764 #include "tnl_dd/t_dd_tritmp.h"
766 #define IND (TRIDENT_OFFSET_BIT)
767 #define TAG(x) x##_offset
768 #include "tnl_dd/t_dd_tritmp.h"
770 #define IND (TRIDENT_TWOSIDE_BIT)
771 #define TAG(x) x##_twoside
772 #include "tnl_dd/t_dd_tritmp.h"
774 #define IND (TRIDENT_TWOSIDE_BIT|TRIDENT_OFFSET_BIT)
775 #define TAG(x) x##_twoside_offset
776 #include "tnl_dd/t_dd_tritmp.h"
778 #define IND (TRIDENT_UNFILLED_BIT)
779 #define TAG(x) x##_unfilled
780 #include "tnl_dd/t_dd_tritmp.h"
782 #define IND (TRIDENT_OFFSET_BIT|TRIDENT_UNFILLED_BIT)
783 #define TAG(x) x##_offset_unfilled
784 #include "tnl_dd/t_dd_tritmp.h"
786 #define IND (TRIDENT_TWOSIDE_BIT|TRIDENT_UNFILLED_BIT)
787 #define TAG(x) x##_twoside_unfilled
788 #include "tnl_dd/t_dd_tritmp.h"
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"
794 #define IND (TRIDENT_FALLBACK_BIT)
795 #define TAG(x) x##_fallback
796 #include "tnl_dd/t_dd_tritmp.h"
798 #define IND (TRIDENT_OFFSET_BIT|TRIDENT_FALLBACK_BIT)
799 #define TAG(x) x##_offset_fallback
800 #include "tnl_dd/t_dd_tritmp.h"
802 #define IND (TRIDENT_TWOSIDE_BIT|TRIDENT_FALLBACK_BIT)
803 #define TAG(x) x##_twoside_fallback
804 #include "tnl_dd/t_dd_tritmp.h"
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"
810 #define IND (TRIDENT_UNFILLED_BIT|TRIDENT_FALLBACK_BIT)
811 #define TAG(x) x##_unfilled_fallback
812 #include "tnl_dd/t_dd_tritmp.h"
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"
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"
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"
826 static void init_rast_tab( void )
831 init_twoside_offset();
833 init_offset_unfilled();
834 init_twoside_unfilled();
835 init_twoside_offset_unfilled();
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();
847 /**********************************************************************/
848 /* Render unclipped begin/end objects */
849 /**********************************************************************/
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 );
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; \
870 #define RESET_STIPPLE if ( stipple ) tridentResetLineStipple( ctx );
871 #define RESET_OCCLUSION
872 #define PRESERVE_VB_DEFS
874 #define TAG(x) trident_##x##_verts
875 #include "tnl/t_vb_rendertmp.h"
878 #define TAG(x) trident_##x##_elts
879 #define ELT(x) elt[x]
880 #include "tnl/t_vb_rendertmp.h"
882 /**********************************************************************/
883 /* Render clipped primitives */
884 /**********************************************************************/
886 static void tridentRenderClippedPoly( GLcontext
*ctx
, const GLuint
*elts
,
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
;
894 /* Render the new vertices as an unclipped polygon.
897 GLuint
*tmp
= VB
->Elts
;
898 VB
->Elts
= (GLuint
*)elts
;
899 tnl
->Driver
.Render
.PrimTabElts
[GL_POLYGON
]( ctx
, 0, n
, PRIM_BEGIN
|PRIM_END
);
903 /* Restore the render primitive
905 if (prim
!= GL_POLYGON
)
906 tnl
->Driver
.Render
.PrimitiveNotify( ctx
, prim
);
909 static void tridentRenderClippedLine( GLcontext
*ctx
, GLuint ii
, GLuint jj
)
911 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
912 tnl
->Driver
.Render
.Line( ctx
, ii
, jj
);
916 /**********************************************************************/
917 /* Choose render functions */
918 /**********************************************************************/
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) \
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)
936 static void tridentChooseRenderState(GLcontext
*ctx
)
938 tridentContextPtr tmesa
= TRIDENT_CONTEXT(ctx
);
939 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
940 GLuint flags
= ctx
->_TriangleCaps
;
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
;
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
;
954 /* Hook in fallbacks for specific primitives.
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
;
964 if (tmesa
->RenderIndex
!= index
) {
965 tmesa
->RenderIndex
= index
;
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
;
972 if (tmesa
->RenderIndex
== 0) {
973 tnl
->Driver
.Render
.PrimTabVerts
= trident_render_tab_verts
;
974 tnl
->Driver
.Render
.PrimTabElts
= trident_render_tab_elts
;
976 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
977 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
979 tnl
->Driver
.Render
.ClippedLine
= tridentRenderClippedLine
;
980 tnl
->Driver
.Render
.ClippedPolygon
= tridentRenderClippedPoly
;
985 /**********************************************************************/
986 /* High level hooks for t_vb_render.c */
987 /**********************************************************************/
991 /* Determine the rasterized primitive when not drawing unfilled
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.
1000 static void tridentRasterPrimitive( GLcontext
*ctx
, GLuint hwprim
)
1002 tridentContextPtr tmesa
= TRIDENT_CONTEXT(ctx
);
1003 if (tmesa
->hw_primitive
!= hwprim
)
1004 tmesa
->hw_primitive
= hwprim
;
1008 static void tridentRenderPrimitive( GLcontext
*ctx
, GLenum prim
)
1010 tridentContextPtr tmesa
= TRIDENT_CONTEXT(ctx
);
1011 tmesa
->render_primitive
= prim
;
1014 static void tridentRunPipeline( GLcontext
*ctx
)
1016 tridentContextPtr tmesa
= TRIDENT_CONTEXT(ctx
);
1018 if ( tmesa
->new_state
)
1019 tridentDDUpdateHWState( ctx
);
1021 if (tmesa
->new_gl_state
) {
1023 if (tmesa
->new_gl_state
& _NEW_TEXTURE
)
1024 tridentUpdateTextureState( ctx
);
1027 if (!tmesa
->Fallback
) {
1028 if (tmesa
->new_gl_state
& _TRIDENT_NEW_VERTEX
)
1029 tridentChooseVertexState( ctx
);
1031 if (tmesa
->new_gl_state
& _TRIDENT_NEW_RENDER_STATE
)
1032 tridentChooseRenderState( ctx
);
1035 tmesa
->new_gl_state
= 0;
1038 _tnl_run_pipeline( ctx
);
1041 static void tridentRenderStart( GLcontext
*ctx
)
1043 /* Check for projective texturing. Make sure all texcoord
1044 * pointers point to something. (fix in mesa?)
1046 tridentCheckTexSizes( ctx
);
1049 static void tridentRenderFinish( GLcontext
*ctx
)
1052 _swrast_flush( ctx
); /* never needed */
1055 static void tridentResetLineStipple( GLcontext
*ctx
)
1057 tridentContextPtr tmesa
= TRIDENT_CONTEXT(ctx
);
1060 /* Reset the hardware stipple counter.
1065 /**********************************************************************/
1066 /* Transition to/from hardware rasterization. */
1067 /**********************************************************************/
1070 void tridentFallback( tridentContextPtr tmesa
, GLuint bit
, GLboolean mode
)
1072 GLcontext
*ctx
= tmesa
->glCtx
;
1073 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1074 GLuint oldfallback
= tmesa
->Fallback
;
1076 _tnl_need_projected_coords( ctx
, GL_FALSE
);
1079 tmesa
->Fallback
|= bit
;
1080 if (oldfallback
== 0) {
1081 _swsetup_Wakeup( ctx
);
1082 tmesa
->RenderIndex
= ~0;
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
);
1101 /**********************************************************************/
1102 /* Initialization. */
1103 /**********************************************************************/
1106 void tridentDDInitTriFuncs( GLcontext
*ctx
)
1108 tridentContextPtr tmesa
= TRIDENT_CONTEXT(ctx
);
1109 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1110 static int firsttime
= 1;
1117 tmesa
->RenderIndex
= ~0;
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
;