4 #define ZCMP(z,zpix) ((z) >= (zpix))
6 void ZB_fillTriangleFlat(ZBuffer
*zb
,
7 ZBufferPoint
*p0
,ZBufferPoint
*p1
,ZBufferPoint
*p2
)
9 #if TGL_FEATURE_RENDER_BITS == 24
10 unsigned char colorR
, colorG
, colorB
;
17 #if TGL_FEATURE_RENDER_BITS == 24
26 #define PUT_PIXEL(_a) \
28 zz=z >> ZB_POINT_Z_FRAC_BITS; \
29 if (ZCMP(zz,pz[_a])) { \
31 pp[3 * _a + 1]=colorG;\
32 pp[3 * _a + 2]=colorB;\
42 color=RGB_TO_PIXEL(p2->r,p2->g,p2->b); \
45 #define PUT_PIXEL(_a) \
47 zz=z >> ZB_POINT_Z_FRAC_BITS; \
48 if (ZCMP(zz,pz[_a])) { \
54 #endif /* TGL_FEATURE_RENDER_BITS == 24 */
56 #include "ztriangle.h"
60 * Smooth filled triangle.
61 * The code below is very tricky :)
64 void ZB_fillTriangleSmooth(ZBuffer
*zb
,
65 ZBufferPoint
*p0
,ZBufferPoint
*p1
,ZBufferPoint
*p2
)
67 #if TGL_FEATURE_RENDER_BITS == 16
74 #define SAR_RND_TO_ZERO(v,n) (v / (1<<n))
76 #if TGL_FEATURE_RENDER_BITS == 24
82 #define PUT_PIXEL(_a) \
84 zz=z >> ZB_POINT_Z_FRAC_BITS; \
85 if (ZCMP(zz,pz[_a])) { \
87 pp[3 * _a + 1]=og1 >> 8;\
88 pp[3 * _a + 2]=ob1 >> 8;\
97 #elif TGL_FEATURE_RENDER_BITS == 16
101 _drgbdx=(SAR_RND_TO_ZERO(drdx,6) << 22) & 0xFFC00000; \
102 _drgbdx|=SAR_RND_TO_ZERO(dgdx,5) & 0x000007FF; \
103 _drgbdx|=(SAR_RND_TO_ZERO(dbdx,7) << 12) & 0x001FF000; \
107 #define PUT_PIXEL(_a) \
109 zz=z >> ZB_POINT_Z_FRAC_BITS; \
110 if (ZCMP(zz,pz[_a])) { \
111 tmp=rgb & 0xF81F07E0; \
112 pp[_a]=tmp | (tmp >> 16); \
116 rgb=(rgb+drgbdx) & ( ~ 0x00200800); \
119 #define DRAW_LINE() \
121 register unsigned short *pz; \
122 register PIXEL *pp; \
123 register unsigned int tmp,z,zz,rgb,drgbdx; \
129 rgb=(r1 << 16) & 0xFFC00000; \
130 rgb|=(g1 >> 5) & 0x000007FF; \
131 rgb|=(b1 << 5) & 0x001FF000; \
152 #define DRAW_INIT() \
156 #define PUT_PIXEL(_a) \
158 zz=z >> ZB_POINT_Z_FRAC_BITS; \
159 if (ZCMP(zz,pz[_a])) { \
160 pp[_a] = RGB_TO_PIXEL(or1, og1, ob1);\
169 #endif /* TGL_FEATURE_RENDER_BITS */
171 #include "ztriangle.h"
174 void ZB_setTexture(ZBuffer
*zb
,PIXEL
*texture
)
176 zb
->current_texture
=texture
;
179 void ZB_fillTriangleMapping(ZBuffer
*zb
,
180 ZBufferPoint
*p0
,ZBufferPoint
*p1
,ZBufferPoint
*p2
)
187 #define DRAW_INIT() \
189 texture=zb->current_texture; \
192 #if TGL_FEATURE_RENDER_BITS == 24
194 #define PUT_PIXEL(_a) \
197 zz=z >> ZB_POINT_Z_FRAC_BITS; \
198 if (ZCMP(zz,pz[_a])) { \
199 ptr = texture + (((t & 0x3FC00000) | s) >> 14) * 3; \
201 pp[3 * _a + 1]= ptr[1];\
202 pp[3 * _a + 2]= ptr[2];\
212 #define PUT_PIXEL(_a) \
214 zz=z >> ZB_POINT_Z_FRAC_BITS; \
215 if (ZCMP(zz,pz[_a])) { \
216 pp[_a]=texture[((t & 0x3FC00000) | s) >> 14]; \
226 #include "ztriangle.h"
230 * Texture mapping with perspective correction.
231 * We use the gradient method to make less divisions.
232 * TODO: pipeline the division
236 void ZB_fillTriangleMappingPerspective(ZBuffer
*zb
,
237 ZBufferPoint
*p0
,ZBufferPoint
*p1
,ZBufferPoint
*p2
)
240 float fdzdx
,fndzdx
,ndszdx
,ndtzdx
;
247 #define DRAW_INIT() \
249 texture=zb->current_texture;\
251 fndzdx=NB_INTERP * fdzdx;\
252 ndszdx=NB_INTERP * dszdx;\
253 ndtzdx=NB_INTERP * dtzdx;\
257 #if TGL_FEATURE_RENDER_BITS == 24
259 #define PUT_PIXEL(_a) \
262 zz=z >> ZB_POINT_Z_FRAC_BITS; \
263 if (ZCMP(zz,pz[_a])) { \
264 ptr = texture + (((t & 0x3FC00000) | (s & 0x003FC000)) >> 14) * 3;\
266 pp[3 * _a + 1]= ptr[1];\
267 pp[3 * _a + 2]= ptr[2];\
277 #define PUT_PIXEL(_a) \
279 zz=z >> ZB_POINT_Z_FRAC_BITS; \
280 if (ZCMP(zz,pz[_a])) { \
281 pp[_a]=*(PIXEL *)((char *)texture+ \
282 (((t & 0x3FC00000) | (s & 0x003FC000)) >> (17 - PSZSH)));\
292 #define DRAW_LINE() \
294 register unsigned short *pz; \
295 register PIXEL *pp; \
296 register unsigned int s,t,z,zz; \
297 register int n,dsdx,dtdx; \
298 float sz,tz,fz,zinv; \
302 pp=(PIXEL *)((char *)pp1 + x1 * PSZB); \
307 while (n>=(NB_INTERP-1)) { \
314 dsdx= (int)( (dszdx - ss*fdzdx)*zinv );\
315 dtdx= (int)( (dtzdx - tt*fdzdx)*zinv );\
328 pp=(PIXEL *)((char *)pp + NB_INTERP * PSZB);\
339 dsdx= (int)( (dszdx - ss*fdzdx)*zinv );\
340 dtdx= (int)( (dtzdx - tt*fdzdx)*zinv );\
345 pp=(PIXEL *)((char *)pp + PSZB);\
350 #include "ztriangle.h"
357 /* slow but exact version (only there for reference, incorrect for 24
360 void ZB_fillTriangleMappingPerspective(ZBuffer
*zb
,
361 ZBufferPoint
*p0
,ZBufferPoint
*p1
,ZBufferPoint
*p2
)
368 #define DRAW_INIT() \
370 texture=zb->current_texture; \
373 #define PUT_PIXEL(_a) \
377 zz=z >> ZB_POINT_Z_FRAC_BITS; \
378 if (ZCMP(zz,pz[_a])) { \
379 zinv= 1.0 / (float) z; \
380 s= (int) (sz * zinv); \
381 t= (int) (tz * zinv); \
382 pp[_a]=texture[((t & 0x3FC00000) | s) >> 14]; \
390 #include "ztriangle.h"