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