Rev 5153 | Rev 5187 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5153 | IgorA | 1 | |
2 | |||
3 | |||
4 | { |
||
5 | if TGL_FEATURE_RENDER_BITS eq 24 |
||
6 | mov ecx,[p2] |
||
7 | mov eax,[ecx+offs_zbup_r] |
||
8 | shr eax,8 |
||
9 | mov [colorR],al ;colorR=p2.r>>8 |
||
5175 | IgorA | 10 | mov eax,[ecx+offs_zbup_g] |
5153 | IgorA | 11 | shr eax,8 |
12 | mov [colorG],al ;colorG=p2.g>>8 |
||
5175 | IgorA | 13 | mov eax,[ecx+offs_zbup_b] |
5153 | IgorA | 14 | shr eax,8 |
15 | mov [colorB],al ;colorB=p2.b>>8 |
||
5175 | IgorA | 16 | else |
5153 | IgorA | 17 | ; color=RGB_TO_PIXEL(p2->r,p2->g,p2->b); |
18 | end if |
||
19 | } |
||
20 | |||
21 | |||
22 | { |
||
23 | local .end_0 |
||
5175 | IgorA | 24 | mov eax,[z] |
25 | shr eax, ZB_POINT_Z_FRAC_BITS |
||
26 | mov [zz],eax |
||
27 | mov ebx,[pz] |
||
28 | cmp ax,word[ebx+2*_a] ;if (zz >= pz[_a]) |
||
29 | jl .end_0 |
||
30 | ;edi = pp |
||
31 | if TGL_FEATURE_RENDER_BITS eq 24 |
||
5153 | IgorA | 32 | mov cl,[colorR] |
5175 | IgorA | 33 | mov ch,[colorG] |
34 | mov word[edi+3*_a],cx |
||
35 | mov cl,[colorB] |
||
36 | mov byte[edi+3*_a +2],cl |
||
37 | else |
||
5153 | IgorA | 38 | ; pp[_a]=color; |
39 | end if |
||
40 | mov word[ebx+2*_a],ax ;пишем в буфер глубины новое значение |
||
5175 | IgorA | 41 | .end_0: |
42 | mov eax,[dzdx] |
||
43 | add [z],eax |
||
44 | } |
||
5153 | IgorA | 45 | |
46 | |||
47 | proc ZB_fillTriangleFlat, zb:dword, p0:dword, p1:dword, p2:dword |
||
48 | locals |
||
49 | if TGL_FEATURE_RENDER_BITS eq 24 |
||
50 | colorR db ? |
||
51 | colorG db ? |
||
52 | colorB db ? ;unsigned char |
||
53 | else |
||
54 | color dd ? ;int |
||
55 | end if |
||
56 | include 'ztriangle.inc' |
||
57 | |||
58 | |||
59 | ; Smooth filled triangle. |
||
60 | ; The code below is very tricky :) |
||
61 | ; |
||
62 | |||
63 | |||
64 | INTERP_RGB equ 1 |
||
65 | |||
66 | |||
67 | { |
||
68 | if TGL_FEATURE_RENDER_BITS eq 16 |
||
69 | ; _drgbdx=((drdx / (1<<6)) << 22) & 0xFFC00000; |
||
70 | ; _drgbdx|=(dgdx / (1<<5)) & 0x000007FF; |
||
71 | ; _drgbdx|=((dbdx / (1<<7)) << 12) & 0x001FF000; |
||
72 | end if |
||
73 | } |
||
74 | |||
75 | |||
76 | { |
||
77 | mov eax,[z] |
||
5175 | IgorA | 78 | shr eax,ZB_POINT_Z_FRAC_BITS |
79 | mov [zz],eax |
||
80 | if TGL_FEATURE_RENDER_BITS eq 24 |
||
5153 | IgorA | 81 | ; if (zz >= pz[_a]) { |
82 | ; pp[3 * _a]=or1 >> 8; |
||
83 | ; pp[3 * _a + 1]=og1 >> 8; |
||
84 | ; pp[3 * _a + 2]=ob1 >> 8; |
||
85 | ; pz[_a]=zz; |
||
86 | ; } |
||
87 | mov eax,[dzdx] |
||
5175 | IgorA | 88 | add [z],eax |
89 | ; og1+=dgdx; |
||
5153 | IgorA | 90 | ; or1+=drdx; |
91 | ; ob1+=dbdx; |
||
92 | elseif TGL_FEATURE_RENDER_BITS eq 16 |
||
93 | ; if (zz >= pz[_a]) { |
||
94 | ; tmp=rgb & 0xF81F07E0; |
||
95 | ; pp[_a]=tmp | (tmp >> 16); |
||
96 | ; pz[_a]=zz; |
||
97 | ; } |
||
98 | ; z+=dzdx; |
||
99 | ; rgb=(rgb+drgbdx) & ( ~ 0x00200800); |
||
100 | else |
||
101 | ; if (zz >= pz[_a]) { |
||
102 | ; pp[_a] = RGB_TO_PIXEL(or1, og1, ob1); |
||
103 | ; pz[_a]=zz; |
||
104 | ; } |
||
105 | mov eax,[dzdx] |
||
5175 | IgorA | 106 | add [z],eax |
107 | ; og1+=dgdx; |
||
5153 | IgorA | 108 | ; or1+=drdx; |
109 | ; ob1+=dbdx; |
||
110 | end if |
||
111 | } |
||
112 | |||
113 | |||
5175 | IgorA | 114 | |
115 | |||
116 | { |
||
5153 | IgorA | 117 | if TGL_FEATURE_RENDER_BITS eq 16 |
118 | if code eq 0 |
||
5175 | IgorA | 119 | ; register unsigned short *pz; |
5153 | IgorA | 120 | ; register PIXEL *pp; |
121 | ; register unsigned int tmp,z,zz,rgb,drgbdx; |
||
122 | ; register int n; |
||
123 | end if |
||
5175 | IgorA | 124 | if code eq 1 |
125 | ; n=(x2 >> 16) - x1; |
||
5153 | IgorA | 126 | ; pp=pp1+x1; |
127 | ; pz=pz1+x1; |
||
128 | ; z=z1; |
||
129 | ; rgb=(r1 << 16) & 0xFFC00000; |
||
130 | ; rgb|=(g1 >> 5) & 0x000007FF; |
||
131 | ; rgb|=(b1 << 5) & 0x001FF000; |
||
132 | ; drgbdx=_drgbdx; |
||
133 | ; while (n>=3) { |
||
134 | ; PUT_PIXEL(0); |
||
135 | ; PUT_PIXEL(1); |
||
136 | ; PUT_PIXEL(2); |
||
137 | ; PUT_PIXEL(3); |
||
138 | ; pz+=4; |
||
139 | ; pp+=4; |
||
140 | ; n-=4; |
||
141 | ; } |
||
142 | ; while (n>=0) { |
||
143 | ; PUT_PIXEL(0); |
||
144 | ; pz+=1; |
||
145 | ; pp+=1; |
||
146 | ; n-=1; |
||
147 | ; } |
||
148 | end if |
||
149 | end if |
||
150 | } |
||
151 | |||
152 | |||
153 | proc ZB_fillTriangleSmooth, zb:dword, p0:dword, p1:dword, p2:dword |
||
154 | locals |
||
155 | if TGL_FEATURE_RENDER_BITS eq 16 |
||
156 | _drgbdx dd ? ;int |
||
157 | end if |
||
158 | include 'ztriangle.inc' |
||
159 | |||
160 | |||
161 | proc ZB_setTexture uses eax ebx, zb:dword, texture:dword |
||
162 | mov eax,[zb] |
||
163 | mov ebx,[texture] |
||
164 | mov dword[eax+offs_zbuf_current_texture],ebx |
||
165 | ret |
||
166 | endp |
||
167 | |||
168 | |||
169 | INTERP_ST equ 1 |
||
170 | |||
171 | |||
172 | { |
||
173 | ; texture=zb->current_texture; |
||
174 | } |
||
175 | |||
176 | |||
177 | { |
||
178 | ; zz=z >> ZB_POINT_Z_FRAC_BITS; |
||
179 | if TGL_FEATURE_RENDER_BITS eq 24 |
||
180 | ; unsigned char *ptr; |
||
181 | ; if (zz >= pz[_a]) { |
||
182 | ; ptr = texture + (((t & 0x3FC00000) | s) >> 14) * 3; |
||
183 | ; pp[3 * _a]= ptr[0]; |
||
184 | ; pp[3 * _a + 1]= ptr[1]; |
||
185 | ; pp[3 * _a + 2]= ptr[2]; |
||
186 | ; pz[_a]=zz; |
||
187 | ; } |
||
188 | else |
||
189 | ; if (zz >= pz[_a]) { |
||
190 | ; pp[_a]=texture[((t & 0x3FC00000) | s) >> 14]; |
||
191 | ; pz[_a]=zz; |
||
192 | ; } |
||
193 | end if |
||
194 | mov eax,[dzdx] |
||
5175 | IgorA | 195 | add [z],eax |
196 | mov eax,[dsdx] |
||
197 | add [s],eax |
||
198 | mov eax,[dtdx] |
||
199 | add [t],eax |
||
200 | } |
||
5153 | IgorA | 201 | |
202 | |||
203 | proc ZB_fillTriangleMapping, zb:dword, p0:dword, p1:dword, p2:dword |
||
204 | locals |
||
205 | texture dd ? ;PIXEL* |
||
206 | include 'ztriangle.inc' |
||
207 | |||
208 | |||
209 | ; Texture mapping with perspective correction. |
||
210 | ; We use the gradient method to make less divisions. |
||
211 | ; TODO: pipeline the division |
||
212 | ; |
||
213 | if 1 |
||
214 | |||
215 | |||
216 | INTERP_STZ equ 1 |
||
217 | |||
218 | |||
219 | |||
220 | |||
221 | { |
||
222 | ; texture=zb->current_texture; |
||
223 | ; fdzdx=(float)dzdx; |
||
224 | ; fndzdx=NB_INTERP * fdzdx; |
||
225 | ; ndszdx=NB_INTERP * dszdx; |
||
226 | ; ndtzdx=NB_INTERP * dtzdx; |
||
227 | } |
||
228 | |||
229 | |||
230 | { |
||
231 | ; zz=z >> ZB_POINT_Z_FRAC_BITS; |
||
232 | if TGL_FEATURE_RENDER_BITS eq 24 |
||
233 | ; unsigned char *ptr; |
||
234 | ; if (zz >= pz[_a]) { |
||
235 | ; ptr = texture + (((t & 0x3FC00000) | (s & 0x003FC000)) >> 14) * 3; |
||
236 | ; pp[3 * _a]= ptr[0]; |
||
237 | ; pp[3 * _a + 1]= ptr[1]; |
||
238 | ; pp[3 * _a + 2]= ptr[2]; |
||
239 | ; pz[_a]=zz; |
||
240 | ; } |
||
241 | else |
||
242 | ; if (zz >= pz[_a]) { |
||
243 | ; pp[_a]=*(PIXEL *)((char *)texture+ |
||
244 | ; (((t & 0x3FC00000) | (s & 0x003FC000)) >> (17 - PSZSH))); |
||
245 | ; pz[_a]=zz; |
||
246 | ; } |
||
247 | end if |
||
248 | mov eax,[dzdx] |
||
5175 | IgorA | 249 | add [z],eax |
250 | mov eax,[dsdx] |
||
251 | add [s],eax |
||
252 | mov eax,[dtdx] |
||
253 | add [t],eax |
||
254 | } |
||
5153 | IgorA | 255 | |
256 | |||
5175 | IgorA | 257 | |
258 | |||
259 | { |
||
260 | if TGL_FEATURE_RENDER_BITS eq 24 |
||
261 | if code eq 0 |
||
262 | pz dd ? ;uint * |
||
263 | ;edi = pp dd ? |
||
264 | s dd ? ;uint |
||
265 | t dd ? ;uint |
||
266 | z dd ? ;uint |
||
267 | zz dd ? ;uint |
||
268 | n dd ? ;int |
||
269 | dsdx dd ? ;int |
||
270 | dtdx dd ? ;int |
||
271 | s_z dd ? ;float |
||
272 | t_z dd ? ;float |
||
273 | fz dd ? ;float |
||
274 | zinv dd ? ;float |
||
275 | end if |
||
276 | if code eq 1 |
||
277 | ; n=(x2>>16)-x1; |
||
278 | ; fz=(float)z1; |
||
279 | ; zinv=1.0 / fz; |
||
280 | ; pp=(pp1 + x1 * PSZB); |
||
281 | ; pz=pz1+x1; |
||
282 | ; z=z1; |
||
283 | ; sz=sz1; |
||
284 | ; tz=tz1; |
||
285 | ; while (n>=(NB_INTERP-1)) { |
||
286 | ; { |
||
287 | ; float ss,tt; |
||
288 | ; ss=(sz * zinv); |
||
289 | ; tt=(tz * zinv); |
||
290 | ; s=(int) ss; |
||
291 | ; t=(int) tt; |
||
292 | ; dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); |
||
293 | ; dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); |
||
294 | ; fz+=fndzdx; |
||
295 | ; zinv=1.0 / fz; |
||
296 | ; } |
||
297 | ; PUT_PIXEL(0); |
||
298 | ; PUT_PIXEL(1); |
||
299 | ; PUT_PIXEL(2); |
||
300 | ; PUT_PIXEL(3); |
||
301 | ; PUT_PIXEL(4); |
||
302 | ; PUT_PIXEL(5); |
||
303 | ; PUT_PIXEL(6); |
||
304 | ; PUT_PIXEL(7); |
||
305 | ; pz+=NB_INTERP; |
||
306 | ; pp=(pp + NB_INTERP * PSZB); |
||
307 | ; n-=NB_INTERP; |
||
308 | ; sz+=ndszdx; |
||
309 | ; tz+=ndtzdx; |
||
310 | ; } |
||
311 | ; { |
||
312 | ; float ss,tt; |
||
313 | ; ss=(sz * zinv); |
||
314 | ; tt=(tz * zinv); |
||
315 | ; s=(int) ss; |
||
316 | ; t=(int) tt; |
||
317 | ; dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); |
||
318 | ; dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); |
||
319 | ; } |
||
320 | ; while (n>=0) { |
||
321 | ; PUT_PIXEL(0); |
||
322 | ; pz+=1; |
||
323 | ; pp=(PIXEL *)((char *)pp + PSZB); |
||
324 | ; n-=1; |
||
325 | ; } |
||
326 | end if |
||
327 | end if |
||
328 | } |
||
329 | |||
330 | |||
5153 | IgorA | 331 | proc ZB_fillTriangleMappingPerspective, zb:dword, p0:dword, p1:dword, p2:dword |
332 | locals |
||
333 | texture dd ? ;PIXEL * |
||
5175 | IgorA | 334 | fdzdx dd ? ;float |
335 | fndzdx dd ? |
||
336 | ndszdx dd ? |
||
337 | ndtzdx dd ? |
||
338 | include 'ztriangle.inc' |
||
5153 | IgorA | 339 | |
340 | |||
341 | |||
342 | |||
343 | |||
344 | |||
345 | ; bits) |
||
346 | |||
347 | |||
348 | INTERP_STZ equ 1 |
||
349 | |||
350 | |||
351 | { |
||
352 | ; texture=zb->current_texture; |
||
353 | } |
||
354 | |||
355 | |||
356 | { |
||
357 | ; float zinv; |
||
358 | ; int s,t; |
||
359 | ; zz=z >> ZB_POINT_Z_FRAC_BITS; |
||
360 | ; if (zz >= pz[_a]) { |
||
361 | ; zinv= 1.0 / (float) z; |
||
362 | ; s= (int) (sz * zinv); |
||
363 | ; t= (int) (tz * zinv); |
||
364 | ; pp[_a]=texture[((t & 0x3FC00000) | s) >> 14]; |
||
365 | ; pz[_a]=zz; |
||
366 | ; } |
||
367 | mov eax,[dzdx] |
||
5175 | IgorA | 368 | add [z],eax |
369 | mov eax,[dszdx] |
||
370 | add [sz],eax |
||
371 | mov eax,[dtzdx] |
||
372 | add [tz],eax |
||
373 | } |
||
5153 | IgorA | 374 | |
375 | |||
376 | proc ZB_fillTriangleMappingPerspective, zb:dword, p0:dword, p1:dword, p2:dword |
||
377 | locals |
||
378 | texture dd ? ;PIXEL* |
||
379 | include 'ztriangle.inc' |
||
380 | |||
381 | |||
382 |