Rev 6113 | Rev 6145 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5153 | IgorA | 1 | ; |
2 | ; We draw a triangle with various interpolations |
||
3 | ; |
||
5922 | IgorA | 4 | ; Порядок преобразований цветов вершин: |
5 | ; ZBufferPoint.r -> r1 (+drdl_min or +drdl_max) -> or1 (+drdx) -> [pixel buffer] |
||
6 | ; ZBufferPoint.g -> g1 (+dgdl_min or +dgdl_max) -> og1 (+dgdx) -> [pixel buffer] |
||
7 | ; ZBufferPoint.b -> b1 (+dbdl_min or +dbdl_max) -> ob1 (+dbdx) -> [pixel buffer] |
||
8 | ; |
||
9 | ; В некоторых случаях значения цвета (во 2-м байте переменных: or1,og1,ob1) |
||
10 | ; может становиться < 0 или > 255, тогда появляються пиксели не правильного |
||
11 | ; цвета. Скорее всего это связано с ошибками округления дробных чисел, |
||
12 | ; при вычислении коэфициентов для плавного перехода цвета. |
||
13 | ; |
||
14 | ; Для лечения этой проблемы в версии на C++ специально ограничиваються |
||
15 | ; минимальные и максимальные значения цвета точек (например от 3 до 252). |
||
16 | ; Потому цвета граней могут немного отличаться от указанных в программе. |
||
17 | ; |
||
18 | ; В даной версии алгоритм немного другой. В наиболее вероятных местах появления |
||
19 | ; пикселей не правильного цвета (обычно начало и конец линии) иправляеться |
||
20 | ; цвет испорченных пикселей. Цвет получаеться наиболее близким к указанному |
||
21 | ; пользователем. |
||
22 | |||
5153 | IgorA | 23 | pr1 dd ? ;ZBufferPoint* |
24 | pr2 dd ? ;ZBufferPoint* |
||
25 | l1 dd ? ;ZBufferPoint* |
||
26 | l2 dd ? ;ZBufferPoint* |
||
5175 | IgorA | 27 | fdx1 dd ? ;float |
28 | fdx2 dd ? ;float |
||
29 | fdy1 dd ? ;float |
||
30 | fdy2 dd ? ;float |
||
6113 | IgorA | 31 | fz dd ? ;float - переменная отвечающая за геометрию фигуры |
5175 | IgorA | 32 | d1 dd ? ;float |
33 | d2 dd ? ;float |
||
5153 | IgorA | 34 | pz1 dd ? ;unsigned short* |
35 | pp1 dd ? ;PIXEL* |
||
36 | part dd ? |
||
37 | update_left dd ? |
||
38 | update_right dd ? |
||
39 | |||
5187 | IgorA | 40 | nb_lines dd ? ;число горизонтальных линий в половине треугольника |
5153 | IgorA | 41 | dx1 dd ? |
42 | dy1 dd ? |
||
5187 | IgorA | 43 | ;dx2 dd ? |
5153 | IgorA | 44 | dy2 dd ? |
45 | |||
5187 | IgorA | 46 | error dd ? ;int |
47 | derror dd ? ;int |
||
48 | x1 dd ? ;int |
||
49 | dxdy_min dd ? ;int |
||
50 | dxdy_max dd ? ;int |
||
5153 | IgorA | 51 | ; warning: x2 is multiplied by 2^16 |
5187 | IgorA | 52 | x2 dd ? ;int |
53 | dx2dy2 dd ? ;int |
||
5153 | IgorA | 54 | |
6108 | IgorA | 55 | z dd ? ;uint |
6113 | IgorA | 56 | n dd ? ;int - длинна горизонтальной линии в пикселях |
57 | |||
5153 | IgorA | 58 | if INTERP_Z eq 1 |
5187 | IgorA | 59 | z1 dd ? ;int |
60 | dzdx dd ? ;int |
||
61 | dzdy dd ? ;int |
||
62 | dzdl_min dd ? ;int |
||
63 | dzdl_max dd ? ;int |
||
5153 | IgorA | 64 | end if |
65 | if INTERP_RGB eq 1 |
||
66 | r1 dd ? ;int |
||
67 | drdx dd ? |
||
68 | drdy dd ? |
||
69 | drdl_min dd ? |
||
70 | drdl_max dd ? |
||
71 | g1 dd ? |
||
72 | dgdx dd ? |
||
73 | dgdy dd ? |
||
74 | dgdl_min dd ? |
||
75 | dgdl_max dd ? |
||
76 | b1 dd ? |
||
77 | dbdx dd ? |
||
78 | dbdy dd ? |
||
79 | dbdl_min dd ? |
||
80 | dbdl_max dd ? |
||
6113 | IgorA | 81 | or1 dd ? ;uint |
82 | og1 dd ? ;uint |
||
83 | ob1 dd ? ;uint |
||
5153 | IgorA | 84 | end if |
85 | if INTERP_ST eq 1 |
||
5187 | IgorA | 86 | s1 dd ? ;int |
87 | dsdy dd ? ;int |
||
88 | dsdl_min dd ? ;int |
||
89 | dsdl_max dd ? ;int |
||
90 | t1 dd ? ;int |
||
91 | dtdy dd ? ;int |
||
92 | dtdl_min dd ? ;int |
||
93 | dtdl_max dd ? ;int |
||
5153 | IgorA | 94 | end if |
95 | if INTERP_STZ eq 1 |
||
5175 | IgorA | 96 | sz1 dd ? ;float |
97 | dszdx dd ? ;float |
||
98 | dszdy dd ? ;float |
||
99 | dszdl_min dd ? ;float |
||
100 | dszdl_max dd ? ;float |
||
101 | tz1 dd ? ;float |
||
102 | dtzdx dd ? ;float |
||
103 | dtzdy dd ? ;float |
||
104 | dtzdl_min dd ? ;float |
||
105 | dtzdl_max dd ? ;float |
||
6108 | IgorA | 106 | s_z dd ? ;float |
107 | t_z dd ? ;float |
||
5153 | IgorA | 108 | end if |
6113 | IgorA | 109 | if (INTERP_ST eq 1) | (DRAW_LINE_M eq 1) |
5175 | IgorA | 110 | s dd ? ;uint |
111 | t dd ? ;uint |
||
6113 | IgorA | 112 | dsdx dd ? ;int |
113 | dtdx dd ? ;int |
||
5175 | IgorA | 114 | end if |
5153 | IgorA | 115 | endl |
5187 | IgorA | 116 | pushad |
5153 | IgorA | 117 | |
5175 | IgorA | 118 | ; we sort the vertex with increasing y |
119 | mov ebx,[p0] |
||
120 | mov ecx,[p1] |
||
121 | mov edx,[p2] |
||
5187 | IgorA | 122 | mov eax,[edx+offs_zbup_y] |
123 | cmp [ecx+offs_zbup_y],eax ;(2-1) |
||
124 | jle @f |
||
125 | xchg edx,ecx |
||
5175 | IgorA | 126 | @@: |
127 | mov eax,[ecx+offs_zbup_y] |
||
5187 | IgorA | 128 | cmp [ebx+offs_zbup_y],eax ;(1-0) |
129 | jle @f |
||
130 | xchg ecx,ebx |
||
131 | @@: |
||
132 | mov eax,[edx+offs_zbup_y] |
||
133 | cmp [ecx+offs_zbup_y],eax ;(2-1) |
||
134 | jle @f |
||
135 | xchg edx,ecx |
||
136 | @@: |
||
137 | mov [p0],ebx |
||
138 | mov [p1],ecx |
||
139 | mov [p2],edx |
||
5153 | IgorA | 140 | |
141 | ; we compute dXdx and dXdy for all interpolated values |
||
5175 | IgorA | 142 | mov eax,[ecx+offs_zbup_x] |
143 | sub eax,[ebx+offs_zbup_x] |
||
144 | mov [fdx1],eax ;p1.x - p0.x |
||
145 | mov eax,[ecx+offs_zbup_y] |
||
146 | sub eax,[ebx+offs_zbup_y] |
||
147 | mov [fdy1],eax ;p1.y - p0.y |
||
5153 | IgorA | 148 | |
5175 | IgorA | 149 | mov eax,[edx+offs_zbup_x] |
150 | sub eax,[ebx+offs_zbup_x] |
||
151 | mov [fdx2],eax ;p2.x - p0.x |
||
152 | mov eax,[edx+offs_zbup_y] |
||
153 | sub eax,[ebx+offs_zbup_y] |
||
154 | mov [fdy2],eax ;p2.y - p0.y |
||
5153 | IgorA | 155 | |
5187 | IgorA | 156 | fild dword[fdx1] |
157 | fst dword[fdx1] |
||
158 | fild dword[fdy2] |
||
159 | fst dword[fdy2] |
||
160 | fmulp |
||
5175 | IgorA | 161 | fild dword[fdx2] |
162 | fst dword[fdx2] |
||
163 | fild dword[fdy1] |
||
164 | fst dword[fdy1] |
||
165 | fmulp |
||
5187 | IgorA | 166 | fsubp ;st0 = st1-st0 |
5175 | IgorA | 167 | fst dword[fz] ;fz = fdx1 * fdy2 - fdx2 * fdy1 |
168 | fldz |
||
5187 | IgorA | 169 | fcompp ;if (fz == 0) return |
5175 | IgorA | 170 | fstsw ax |
171 | sahf |
||
172 | je .end_f |
||
5189 | IgorA | 173 | |
5175 | IgorA | 174 | fld1 |
175 | fdiv dword[fz] ;fz = 1.0 / fz |
||
176 | fst dword[fz] ;st0 = fz |
||
5153 | IgorA | 177 | |
5175 | IgorA | 178 | fld dword[fdx1] |
179 | fmul st0,st1 |
||
180 | fstp dword[fdx1] ;fdx1 *= fz |
||
181 | fld dword[fdy1] |
||
182 | fmul st0,st1 |
||
183 | fstp dword[fdy1] ;fdy1 *= fz |
||
184 | fld dword[fdx2] |
||
185 | fmul st0,st1 |
||
186 | fstp dword[fdx2] ;fdx2 *= fz |
||
187 | fld dword[fdy2] |
||
188 | fmul st0,st1 |
||
189 | fstp dword[fdy2] ;fdy2 *= fz |
||
190 | ffree st0 |
||
191 | fincstp |
||
5153 | IgorA | 192 | |
193 | if INTERP_Z eq 1 |
||
5175 | IgorA | 194 | mov eax,[ecx+offs_zbup_z] |
195 | sub eax,[ebx+offs_zbup_z] |
||
196 | mov [d1],eax |
||
197 | mov eax,[edx+offs_zbup_z] |
||
198 | sub eax,[ebx+offs_zbup_z] |
||
199 | mov [d2],eax |
||
5187 | IgorA | 200 | fild dword[d1] ;d1 = p1.z - p0.z |
201 | fild dword[d2] ;d2 = p2.z - p0.z |
||
5175 | IgorA | 202 | |
5187 | IgorA | 203 | fld dword[fdy2] |
204 | fmul st0,st2 |
||
5175 | IgorA | 205 | fld dword[fdy1] |
5187 | IgorA | 206 | fmul st0,st2 |
207 | fsubp |
||
208 | fistp dword[dzdx] ;dzdx = (int) (fdy2*d1 - fdy1*d2) |
||
209 | fld dword[fdx1] |
||
5175 | IgorA | 210 | fmul st0,st1 |
5187 | IgorA | 211 | fld dword[fdx2] |
5175 | IgorA | 212 | fmul st0,st3 |
5187 | IgorA | 213 | fsubp |
5175 | IgorA | 214 | fistp dword[dzdy] ;dzdy = (int) (fdx1*d2 - fdx2*d1) |
5187 | IgorA | 215 | ffree st0 ;free d2 |
5175 | IgorA | 216 | fincstp |
5187 | IgorA | 217 | ffree st0 ;free d1 |
218 | fincstp |
||
5153 | IgorA | 219 | end if |
220 | |||
221 | if INTERP_RGB eq 1 |
||
5175 | IgorA | 222 | mov eax,[ecx+offs_zbup_r] |
223 | sub eax,[ebx+offs_zbup_r] |
||
224 | mov [d1],eax |
||
225 | mov eax,[edx+offs_zbup_r] |
||
226 | sub eax,[ebx+offs_zbup_r] |
||
227 | mov [d2],eax |
||
5187 | IgorA | 228 | fild dword[d1] ;d1 = p1.r - p0.r |
229 | fild dword[d2] ;d2 = p2.r - p0.r |
||
5153 | IgorA | 230 | |
5187 | IgorA | 231 | fld dword[fdy2] |
232 | fmul st0,st2 |
||
5175 | IgorA | 233 | fld dword[fdy1] |
5187 | IgorA | 234 | fmul st0,st2 |
235 | fsubp |
||
236 | fistp dword[drdx] ;drdx = (int) (fdy2*d1 - fdy1*d2) |
||
237 | fld dword[fdx1] |
||
5175 | IgorA | 238 | fmul st0,st1 |
5187 | IgorA | 239 | fld dword[fdx2] |
5175 | IgorA | 240 | fmul st0,st3 |
5187 | IgorA | 241 | fsubp |
5175 | IgorA | 242 | fistp dword[drdy] ;drdy = (int) (fdx1*d2 - fdx2*d1) |
5187 | IgorA | 243 | ffree st0 ;free d2 |
5175 | IgorA | 244 | fincstp |
5187 | IgorA | 245 | ffree st0 ;free d1 |
246 | fincstp |
||
5153 | IgorA | 247 | |
5175 | IgorA | 248 | mov eax,[ecx+offs_zbup_g] |
249 | sub eax,[ebx+offs_zbup_g] |
||
250 | mov [d1],eax |
||
251 | mov eax,[edx+offs_zbup_g] |
||
252 | sub eax,[ebx+offs_zbup_g] |
||
253 | mov [d2],eax |
||
5187 | IgorA | 254 | fild dword[d1] ;d1 = p1.g - p0.g |
255 | fild dword[d2] ;d2 = p2.g - p0.g |
||
5153 | IgorA | 256 | |
5187 | IgorA | 257 | fld dword[fdy2] |
258 | fmul st0,st2 |
||
5175 | IgorA | 259 | fld dword[fdy1] |
5187 | IgorA | 260 | fmul st0,st2 |
261 | fsubp |
||
262 | fistp dword[dgdx] ;dgdx = (int) (fdy2*d1 - fdy1*d2) |
||
263 | fld dword[fdx1] |
||
5175 | IgorA | 264 | fmul st0,st1 |
5187 | IgorA | 265 | fld dword[fdx2] |
5175 | IgorA | 266 | fmul st0,st3 |
5187 | IgorA | 267 | fsubp |
5175 | IgorA | 268 | fistp dword[dgdy] ;dgdy = (int) (fdx1*d2 - fdx2*d1) |
5187 | IgorA | 269 | ffree st0 ;free d2 |
5175 | IgorA | 270 | fincstp |
5187 | IgorA | 271 | ffree st0 ;free d1 |
272 | fincstp |
||
5175 | IgorA | 273 | |
274 | mov eax,[ecx+offs_zbup_b] |
||
275 | sub eax,[ebx+offs_zbup_b] |
||
276 | mov [d1],eax |
||
277 | mov eax,[edx+offs_zbup_b] |
||
278 | sub eax,[ebx+offs_zbup_b] |
||
279 | mov [d2],eax |
||
5187 | IgorA | 280 | fild dword[d1] ;d1 = p1.b - p0.b |
281 | fild dword[d2] ;d2 = p2.b - p0.b |
||
5175 | IgorA | 282 | |
5187 | IgorA | 283 | fld dword[fdy2] |
284 | fmul st0,st2 |
||
5175 | IgorA | 285 | fld dword[fdy1] |
5187 | IgorA | 286 | fmul st0,st2 |
287 | fsubp |
||
288 | fistp dword[dbdx] ;dbdx = (int) (fdy2*d1 - fdy1*d2) |
||
289 | fld dword[fdx1] |
||
5175 | IgorA | 290 | fmul st0,st1 |
5187 | IgorA | 291 | fld dword[fdx2] |
5175 | IgorA | 292 | fmul st0,st3 |
5187 | IgorA | 293 | fsubp |
5175 | IgorA | 294 | fistp dword[dbdy] ;dbdy = (int) (fdx1*d2 - fdx2*d1) |
5187 | IgorA | 295 | ffree st0 ;free d2 |
5175 | IgorA | 296 | fincstp |
5187 | IgorA | 297 | ffree st0 ;free d1 |
298 | fincstp |
||
5153 | IgorA | 299 | end if |
300 | |||
301 | if INTERP_ST eq 1 |
||
5175 | IgorA | 302 | mov eax,[ecx+offs_zbup_s] |
303 | sub eax,[ebx+offs_zbup_s] |
||
304 | mov [d1],eax |
||
305 | mov eax,[edx+offs_zbup_s] |
||
306 | sub eax,[ebx+offs_zbup_s] |
||
307 | mov [d2],eax |
||
5187 | IgorA | 308 | fild dword[d1] ;d1 = p1.s - p0.s |
309 | fild dword[d2] ;d2 = p2.s - p0.s |
||
5153 | IgorA | 310 | |
5187 | IgorA | 311 | fld dword[fdy2] |
312 | fmul st0,st2 |
||
5175 | IgorA | 313 | fld dword[fdy1] |
5187 | IgorA | 314 | fmul st0,st2 |
315 | fsubp |
||
5175 | IgorA | 316 | fistp dword[dsdx] ;dsdx = (int) (fdy2*d1 - fdy1*d2) |
317 | fld dword[fdx2] |
||
318 | fmul st0,st2 |
||
319 | fld dword[fdx1] |
||
320 | fmul st0,st2 |
||
321 | fsub st0,st1 |
||
322 | fistp dword[dsdy] ;dsdy = (int) (fdx1*d2 - fdx2*d1) |
||
323 | ffree st0 |
||
324 | fincstp |
||
5187 | IgorA | 325 | ffree st0 ;free d2 |
326 | fincstp |
||
327 | ffree st0 ;free d1 |
||
328 | fincstp |
||
5175 | IgorA | 329 | |
330 | mov eax,[ecx+offs_zbup_t] |
||
331 | sub eax,[ebx+offs_zbup_t] |
||
332 | mov [d1],eax |
||
333 | mov eax,[edx+offs_zbup_t] |
||
334 | sub eax,[ebx+offs_zbup_t] |
||
335 | mov [d2],eax |
||
5187 | IgorA | 336 | fild dword[d1] ;d1 = p1.t - p0.t |
337 | fild dword[d2] ;d2 = p2.t - p0.t |
||
5175 | IgorA | 338 | |
339 | fld dword[fdy1] |
||
340 | fmul st0,st1 |
||
341 | fld dword[fdy2] |
||
342 | fmul st0,st3 |
||
343 | fsub st0,st1 |
||
344 | fistp dword[dtdx] ;dtdx = (int) (fdy2*d1 - fdy1*d2) |
||
345 | ffree st0 |
||
346 | fincstp |
||
347 | fld dword[fdx2] |
||
348 | fmul st0,st2 |
||
349 | fld dword[fdx1] |
||
350 | fmul st0,st2 |
||
351 | fsub st0,st1 |
||
352 | fistp dword[dtdy] ;dtdy = (int) (fdx1*d2 - fdx2*d1) |
||
353 | ffree st0 |
||
354 | fincstp |
||
5187 | IgorA | 355 | ffree st0 ;free d2 |
356 | fincstp |
||
357 | ffree st0 ;free d1 |
||
358 | fincstp |
||
5153 | IgorA | 359 | end if |
360 | |||
361 | if INTERP_STZ eq 1 |
||
5175 | IgorA | 362 | fild dword[ebx+offs_zbup_z] |
363 | fild dword[ebx+offs_zbup_s] |
||
364 | fmul st0,st1 |
||
365 | fstp dword[ebx+offs_zbup_sz] ;p0.sz = (float) p0.s * p0.z |
||
366 | fild dword[ebx+offs_zbup_t] |
||
5187 | IgorA | 367 | fmulp |
5175 | IgorA | 368 | fstp dword[ebx+offs_zbup_tz] ;p0.tz = (float) p0.t * p0.z |
5153 | IgorA | 369 | |
5175 | IgorA | 370 | fild dword[ecx+offs_zbup_z] |
371 | fild dword[ecx+offs_zbup_s] |
||
372 | fmul st0,st1 |
||
373 | fstp dword[ecx+offs_zbup_sz] ;p1.sz = (float) p1.s * p1.z |
||
374 | fild dword[ecx+offs_zbup_t] |
||
5187 | IgorA | 375 | fmulp |
5175 | IgorA | 376 | fstp dword[ecx+offs_zbup_tz] ;p1.tz = (float) p1.t * p1.z |
5153 | IgorA | 377 | |
5175 | IgorA | 378 | fild dword[edx+offs_zbup_z] |
379 | fild dword[edx+offs_zbup_s] |
||
380 | fmul st0,st1 |
||
381 | fstp dword[edx+offs_zbup_sz] ;p2.sz = (float) p2.s * p2.z |
||
382 | fild dword[edx+offs_zbup_t] |
||
5187 | IgorA | 383 | fmulp |
5175 | IgorA | 384 | fstp dword[edx+offs_zbup_tz] ;p2.tz = (float) p2.t * p2.z |
385 | |||
386 | fld dword[ecx+offs_zbup_sz] |
||
5187 | IgorA | 387 | fsub dword[ebx+offs_zbup_sz] ;d1 = p1.sz - p0.sz |
5175 | IgorA | 388 | fld dword[edx+offs_zbup_sz] |
5187 | IgorA | 389 | fsub dword[ebx+offs_zbup_sz] ;d2 = p2.sz - p0.sz |
5175 | IgorA | 390 | |
5187 | IgorA | 391 | fld dword[fdy2] |
392 | fmul st0,st2 |
||
5175 | IgorA | 393 | fld dword[fdy1] |
5187 | IgorA | 394 | fmul st0,st2 |
395 | fsubp |
||
396 | fstp dword[dszdx] ;dszdx = (fdy2*d1 - fdy1*d2) |
||
5175 | IgorA | 397 | fld dword[fdx2] |
398 | fmul st0,st2 |
||
399 | fld dword[fdx1] |
||
400 | fmul st0,st2 |
||
401 | fsub st0,st1 |
||
5187 | IgorA | 402 | fstp dword[dszdy] ;dszdy = (fdx1*d2 - fdx2*d1) |
5175 | IgorA | 403 | ffree st0 |
404 | fincstp |
||
5187 | IgorA | 405 | ffree st0 ;free d2 |
406 | fincstp |
||
407 | ffree st0 ;free d1 |
||
408 | fincstp |
||
5175 | IgorA | 409 | |
410 | fld dword[ecx+offs_zbup_tz] |
||
5187 | IgorA | 411 | fsub dword[ebx+offs_zbup_tz] ;d1 = p1.tz - p0.tz |
5175 | IgorA | 412 | fld dword[edx+offs_zbup_tz] |
5187 | IgorA | 413 | fsub dword[ebx+offs_zbup_tz] ;d2 = p2.tz - p0.tz |
5175 | IgorA | 414 | |
415 | fld dword[fdy1] |
||
416 | fmul st0,st1 |
||
417 | fld dword[fdy2] |
||
418 | fmul st0,st3 |
||
419 | fsub st0,st1 |
||
5187 | IgorA | 420 | fstp dword[dtzdx] ;dtzdx = (fdy2*d1 - fdy1*d2) |
5175 | IgorA | 421 | ffree st0 |
422 | fincstp |
||
423 | fld dword[fdx2] |
||
424 | fmul st0,st2 |
||
425 | fld dword[fdx1] |
||
426 | fmul st0,st2 |
||
427 | fsub st0,st1 |
||
5187 | IgorA | 428 | fstp dword[dtzdy] ;dtzdy = (fdx1*d2 - fdx2*d1) |
5175 | IgorA | 429 | ffree st0 |
430 | fincstp |
||
5187 | IgorA | 431 | ffree st0 ;free d2 |
432 | fincstp |
||
433 | ffree st0 ;free d1 |
||
434 | fincstp |
||
5153 | IgorA | 435 | end if |
436 | |||
437 | ; screen coordinates |
||
5175 | IgorA | 438 | mov eax,[zb] |
439 | mov edx,[eax+offs_zbuf_linesize] |
||
440 | imul edx,[ebx+offs_zbup_y] |
||
441 | add edx,[eax+offs_zbuf_pbuf] |
||
442 | mov [pp1],edx ;pp1 = zb.pbuf + zb.linesize * p0.y |
||
443 | mov edx,[eax+offs_zbuf_xsize] |
||
444 | imul edx,[ebx+offs_zbup_y] |
||
445 | shl edx,1 |
||
446 | add edx,[eax+offs_zbuf_zbuf] |
||
447 | mov [pz1],edx ;pz1 = zb.zbuf + zb.xsize * p0.y |
||
5153 | IgorA | 448 | |
449 | DRAW_INIT |
||
450 | |||
5175 | IgorA | 451 | mov dword[part],0 |
452 | .cycle_0: |
||
453 | mov ebx,[p0] |
||
454 | mov ecx,[p1] |
||
455 | mov edx,[p2] |
||
5187 | IgorA | 456 | cmp dword[part],0 ;if (part == 0) |
5175 | IgorA | 457 | jne .els_0 |
458 | mov dword[update_left],1 |
||
459 | mov dword[update_right],1 |
||
460 | mov [l1],ebx |
||
461 | mov [pr1],ebx |
||
462 | fldz |
||
463 | fld dword[fz] |
||
464 | fcompp ;if (fz > 0) |
||
465 | fstsw ax |
||
466 | sahf |
||
467 | jbe .els_1 |
||
468 | mov [l2],edx |
||
469 | mov [pr2],ecx |
||
470 | jmp .end_1 |
||
471 | .els_1: |
||
472 | mov [l2],ecx |
||
473 | mov [pr2],edx |
||
474 | .end_1: |
||
475 | mov eax,[ecx+offs_zbup_y] |
||
476 | sub eax,[ebx+offs_zbup_y] |
||
477 | mov [nb_lines],eax ;nb_lines = p1.y - p0.y |
||
478 | jmp .end_0 |
||
479 | .els_0: |
||
480 | ; second part |
||
481 | fldz |
||
482 | fld dword[fz] |
||
483 | fcompp ;if (fz > 0) |
||
484 | fstsw ax |
||
485 | sahf |
||
486 | jbe .els_2 |
||
5187 | IgorA | 487 | mov dword[update_left],0 |
488 | mov dword[update_right],1 |
||
5175 | IgorA | 489 | mov [pr1],ecx |
490 | mov [pr2],edx |
||
491 | jmp .end_2 |
||
492 | .els_2: |
||
5187 | IgorA | 493 | mov dword[update_left],1 |
494 | mov dword[update_right],0 |
||
5175 | IgorA | 495 | mov [l1],ecx |
496 | mov [l2],edx |
||
497 | .end_2: |
||
498 | mov eax,[edx+offs_zbup_y] |
||
499 | sub eax,[ecx+offs_zbup_y] |
||
500 | inc eax |
||
501 | mov [nb_lines],eax ;nb_lines = p2.y - p1.y + 1 |
||
502 | .end_0: |
||
5153 | IgorA | 503 | |
504 | ; compute the values for the left edge |
||
5175 | IgorA | 505 | cmp dword[update_left],0 ;if (update_left) |
506 | je .end_upd_l |
||
507 | mov ebx,[l1] |
||
508 | mov ecx,[l2] |
||
5187 | IgorA | 509 | mov edx,[ecx+offs_zbup_y] |
510 | sub edx,[ebx+offs_zbup_y] |
||
511 | mov [dy1],edx ;dy1 = l2.y - l1.y |
||
5175 | IgorA | 512 | mov eax,[ecx+offs_zbup_x] |
513 | sub eax,[ebx+offs_zbup_x] |
||
514 | mov [dx1],eax ;dx1 = l2.x - l1.x |
||
5187 | IgorA | 515 | cmp edx,0 ;if (dy1 > 0) |
5175 | IgorA | 516 | jle .els_3 |
5187 | IgorA | 517 | xor edx,edx |
518 | cmp eax,0 |
||
519 | jl .otr_dx1 |
||
5175 | IgorA | 520 | shl eax,16 |
521 | div dword[dy1] ;eax = (dx1 << 16) / dy1 |
||
522 | jmp .end_3 |
||
5187 | IgorA | 523 | .otr_dx1: |
524 | neg eax |
||
525 | inc eax |
||
526 | shl eax,16 |
||
527 | div dword[dy1] ;eax = (-dx1 << 16) / dy1 |
||
528 | neg eax |
||
529 | inc eax |
||
530 | jmp .end_3 |
||
5175 | IgorA | 531 | .els_3: |
532 | xor eax,eax |
||
533 | .end_3: |
||
534 | mov edx,[ebx+offs_zbup_x] |
||
5187 | IgorA | 535 | mov [x1],edx ;x1 = l1.x |
536 | mov dword[error],0 ;error = 0 |
||
5175 | IgorA | 537 | mov dword[derror],eax |
5187 | IgorA | 538 | and dword[derror],0xffff ;derror = eax & 0x0000ffff |
5208 | IgorA | 539 | sar eax,16 |
5187 | IgorA | 540 | mov [dxdy_min],eax ;dxdy_min = eax >> 16 |
5175 | IgorA | 541 | inc eax |
542 | mov [dxdy_max],eax |
||
5153 | IgorA | 543 | |
544 | if INTERP_Z eq 1 |
||
5175 | IgorA | 545 | mov eax,[l1] |
546 | mov eax,[eax+offs_zbup_z] |
||
547 | mov [z1],eax ;z1 = l1.z |
||
548 | mov eax,[dzdx] |
||
549 | imul eax,[dxdy_min] |
||
550 | add eax,[dzdy] |
||
551 | mov [dzdl_min],eax ;dzdl_min = (dzdy +dzdx*dxdy_min) |
||
552 | add eax,[dzdx] |
||
553 | mov [dzdl_max],eax ;dzdl_max = dzdl_min +dzdx |
||
5153 | IgorA | 554 | end if |
555 | if INTERP_RGB eq 1 |
||
5175 | IgorA | 556 | mov ebx,[l1] |
557 | mov eax,[ebx+offs_zbup_r] |
||
558 | mov [r1],eax ;r1 = l1.r |
||
559 | mov eax,[drdx] |
||
560 | imul eax,[dxdy_min] |
||
561 | add eax,[drdy] |
||
562 | mov [drdl_min],eax ;drdl_min = (drdy +drdx*dxdy_min) |
||
563 | add eax,[drdx] |
||
564 | mov [drdl_max],eax ;drdl_max = drdl_min +drdx |
||
5153 | IgorA | 565 | |
5175 | IgorA | 566 | mov eax,[ebx+offs_zbup_g] |
567 | mov [g1],eax ;g1 = l1.g |
||
568 | mov eax,[dgdx] |
||
569 | imul eax,[dxdy_min] |
||
570 | add eax,[dgdy] |
||
571 | mov [dgdl_min],eax ;dgdl_min = (dgdy +dgdx*dxdy_min) |
||
572 | add eax,[dgdx] |
||
573 | mov [dgdl_max],eax ;dgdl_max = dgdl_min +dgdx |
||
5153 | IgorA | 574 | |
5175 | IgorA | 575 | mov eax,[ebx+offs_zbup_b] |
576 | mov [b1],eax ;b1 = l1.b |
||
577 | mov eax,[dbdx] |
||
578 | imul eax,[dxdy_min] |
||
579 | add eax,[dbdy] |
||
580 | mov [dbdl_min],eax ;dbdl_min = (dbdy +dbdx*dxdy_min) |
||
581 | add eax,[dbdx] |
||
582 | mov [dbdl_max],eax ;dbdl_max = dbdl_min +dbdx |
||
5153 | IgorA | 583 | end if |
584 | if INTERP_ST eq 1 |
||
5175 | IgorA | 585 | mov ebx,[l1] |
586 | mov eax,[ebx+offs_zbup_s] |
||
587 | mov [s1],eax ;s1 = l1.s |
||
588 | mov eax,[dsdx] |
||
589 | imul eax,[dxdy_min] |
||
590 | add eax,[dsdy] |
||
591 | mov [dsdl_min],eax ;dsdl_min = (dsdy +dsdx*dxdy_min) |
||
592 | add eax,[dsdx] |
||
593 | mov [dsdl_max],eax ;dsdl_max = dsdl_min +dsdx |
||
5153 | IgorA | 594 | |
5175 | IgorA | 595 | mov eax,[ebx+offs_zbup_t] |
596 | mov [t1],eax ;t1 = l1.t |
||
597 | mov eax,[dtdx] |
||
598 | imul eax,[dxdy_min] |
||
599 | add eax,[dtdy] |
||
600 | mov [dtdl_min],eax ;dtdl_min = (dtdy +dtdx*dxdy_min) |
||
601 | add eax,[dtdx] |
||
602 | mov [dtdl_max],eax ;dtdl_max = dtdl_min +dtdx |
||
5153 | IgorA | 603 | end if |
604 | if INTERP_STZ eq 1 |
||
5175 | IgorA | 605 | mov ebx,[l1] |
606 | mov eax,[ebx+offs_zbup_sz] |
||
607 | mov [sz1],eax ;sz1 = l1.sz - преобразований нет, потому без сопроцессора |
||
608 | fild dword[dxdy_min] |
||
609 | fmul dword[dszdx] |
||
610 | fadd dword[dszdy] |
||
611 | fst dword[dszdl_min] ;dszdl_min = (dszdy +dszdx*dxdy_min) |
||
612 | fadd dword[dszdx] |
||
613 | fstp dword[dszdl_max] ;dszdl_max = dszdl_min +dszdx |
||
5153 | IgorA | 614 | |
5175 | IgorA | 615 | mov eax,[ebx+offs_zbup_tz] |
616 | mov [tz1],eax ;tz1 = l1.tz - преобразований нет, потому без сопроцессора |
||
617 | fild dword[dxdy_min] |
||
618 | fmul dword[dtzdx] |
||
619 | fadd dword[dtzdy] |
||
620 | fst dword[dtzdl_min] ;dtzdl_min = (dtzdy +dtzdx*dxdy_min) |
||
621 | fadd dword[dtzdx] |
||
622 | fstp dword[dtzdl_max] ;dtzdl_max = dtzdl_min +dtzdx |
||
5153 | IgorA | 623 | end if |
5175 | IgorA | 624 | .end_upd_l: |
5153 | IgorA | 625 | |
5175 | IgorA | 626 | ; compute values for the right edge |
5153 | IgorA | 627 | |
5175 | IgorA | 628 | cmp dword[update_right],0 ;if(update_right) |
629 | je .end_upd_r |
||
630 | mov ebx,[pr1] |
||
631 | mov ecx,[pr2] |
||
5187 | IgorA | 632 | mov edx,[ebx+offs_zbup_x] |
5175 | IgorA | 633 | mov eax,[ecx+offs_zbup_x] |
5187 | IgorA | 634 | sub eax,edx |
635 | ;mov [dx2],eax ;dx2 = pr2.x - pr1.x |
||
636 | shl edx,16 |
||
637 | mov [x2],edx ; x2 = pr1.x << 16 |
||
638 | mov edx,[ecx+offs_zbup_y] |
||
639 | sub edx,[ebx+offs_zbup_y] |
||
640 | mov [dy2],edx ;dy2 = pr2.y - pr1.y |
||
641 | cmp edx,0 ;if (dy2 > 0) |
||
5175 | IgorA | 642 | jle .els_4 |
5187 | IgorA | 643 | xor edx,edx |
644 | cmp eax,0 |
||
645 | jl .otr_dx2 |
||
5175 | IgorA | 646 | shl eax,16 |
647 | div dword[dy2] ;eax = (dx2 << 16) / dy2 |
||
648 | jmp .end_4 |
||
5187 | IgorA | 649 | .otr_dx2: |
650 | neg eax |
||
651 | inc eax ;dx2 *= -1 |
||
652 | shl eax,16 |
||
653 | div dword[dy2] ;eax = (-dx2 << 16) / dy2 |
||
654 | neg eax |
||
655 | inc eax |
||
656 | jmp .end_4 |
||
5175 | IgorA | 657 | .els_4: |
658 | xor eax,eax |
||
659 | .end_4: |
||
660 | mov [dx2dy2],eax |
||
661 | .end_upd_r: |
||
5153 | IgorA | 662 | |
5175 | IgorA | 663 | ; we draw all the scan line of the part |
5187 | IgorA | 664 | if DEBUG ;[nb_lines] |
665 | push ecx edi |
||
666 | mov eax,[nb_lines] |
||
667 | mov ecx,80 |
||
668 | lea edi,[buf_param] |
||
669 | stdcall convert_int_to_str,ecx |
||
5153 | IgorA | 670 | |
5187 | IgorA | 671 | stdcall str_n_cat,edi,txt_nl,2 |
672 | stdcall dbg_print,f_fill_tr_nl,buf_param |
||
673 | pop edi ecx |
||
674 | end if |
||
675 | |||
5175 | IgorA | 676 | .beg_w_lin: |
677 | cmp dword[nb_lines],0 ;while (nb_lines>0) |
||
678 | jle .end_w_lin |
||
679 | dec dword[nb_lines] |
||
680 | if DRAW_LINE_M eq 1 |
||
6113 | IgorA | 681 | DRAW_LINE |
5175 | IgorA | 682 | else |
683 | ; generic draw line |
||
684 | mov eax,[x2] |
||
5208 | IgorA | 685 | sar eax,16 |
5175 | IgorA | 686 | mov edi,[x1] |
687 | sub eax,edi |
||
688 | mov [n],eax ;n = (x2 >> 16) - x1 |
||
689 | imul edi,PSZB |
||
690 | add edi,[pp1] ;pp = pp1 + x1 * PSZB |
||
5187 | IgorA | 691 | |
5153 | IgorA | 692 | if INTERP_Z eq 1 |
6126 | IgorA | 693 | mov esi,[x1] |
694 | shl esi,1 |
||
695 | add esi,[pz1] |
||
5175 | IgorA | 696 | mov eax,[z1] |
697 | mov [z],eax |
||
5153 | IgorA | 698 | end if |
699 | if INTERP_RGB eq 1 |
||
5175 | IgorA | 700 | mov eax,[r1] |
5922 | IgorA | 701 | bt eax,31 ; коректирование испорченных пикселей (в начале линии) |
702 | jnc @f |
||
703 | xor eax,eax |
||
704 | @@: |
||
705 | bt eax,16 |
||
706 | jnc @f |
||
707 | mov eax,0xff00 |
||
708 | @@: |
||
5175 | IgorA | 709 | mov [or1],eax |
710 | mov eax,[g1] |
||
5922 | IgorA | 711 | bt eax,31 |
712 | jnc @f |
||
713 | xor eax,eax |
||
714 | @@: |
||
715 | bt eax,16 |
||
716 | jnc @f |
||
717 | mov eax,0xff00 |
||
718 | @@: |
||
5175 | IgorA | 719 | mov [og1],eax |
720 | mov eax,[b1] |
||
5922 | IgorA | 721 | bt eax,31 |
722 | jnc @f |
||
723 | xor eax,eax |
||
724 | @@: |
||
725 | bt eax,16 |
||
726 | jnc @f |
||
727 | mov eax,0xff00 |
||
728 | @@: |
||
5175 | IgorA | 729 | mov [ob1],eax |
5153 | IgorA | 730 | end if |
731 | if INTERP_ST eq 1 |
||
5175 | IgorA | 732 | mov eax,[s1] |
733 | mov [s],eax |
||
734 | mov eax,[t1] |
||
735 | mov [t],eax |
||
5153 | IgorA | 736 | end if |
737 | if INTERP_STZ eq 1 |
||
5175 | IgorA | 738 | mov eax,[sz1] |
739 | mov [s_z],eax |
||
740 | mov eax,[tz1] |
||
741 | mov [t_z],eax |
||
5153 | IgorA | 742 | end if |
5187 | IgorA | 743 | |
744 | align 4 |
||
5175 | IgorA | 745 | .cycle_1: ;while (n>=3) |
5922 | IgorA | 746 | if INTERP_RGB eq 1 |
747 | cmp dword[n],5 |
||
748 | jl .cycle_2 |
||
749 | else |
||
5187 | IgorA | 750 | cmp dword[n],3 |
751 | jl .cycle_2 |
||
5922 | IgorA | 752 | end if |
5175 | IgorA | 753 | PUT_PIXEL 0 |
754 | PUT_PIXEL 1 |
||
755 | PUT_PIXEL 2 |
||
756 | PUT_PIXEL 3 |
||
5153 | IgorA | 757 | if INTERP_Z eq 1 |
6126 | IgorA | 758 | add esi,8 ;=4*sizeof(uint) |
5153 | IgorA | 759 | end if |
5175 | IgorA | 760 | add edi,4*PSZB |
761 | sub dword[n],4 |
||
5187 | IgorA | 762 | jmp .cycle_1 |
5175 | IgorA | 763 | .cycle_2: ;while (n>=0) |
5939 | IgorA | 764 | cmp dword[n],0 |
765 | jl .cycle_2_end |
||
5922 | IgorA | 766 | if INTERP_RGB eq 1 |
767 | ; коректирование испорченных пикселей (в конце линии) |
||
768 | bt dword[or1],31 |
||
769 | jnc @f |
||
770 | mov dword[or1],0 |
||
771 | jmp .end_r |
||
772 | @@: |
||
773 | bt dword[or1],16 |
||
774 | jnc .end_r |
||
775 | mov dword[or1],0xff00 |
||
776 | .end_r: |
||
777 | bt dword[og1],31 |
||
778 | jnc @f |
||
779 | mov dword[og1],0 |
||
780 | jmp .end_g |
||
781 | @@: |
||
782 | bt dword[og1],16 |
||
783 | jnc .end_g |
||
784 | mov dword[og1],0xff00 |
||
785 | .end_g: |
||
786 | bt dword[ob1],31 |
||
787 | jnc @f |
||
788 | mov dword[ob1],0 |
||
789 | jmp .end_b |
||
790 | @@: |
||
791 | bt dword[ob1],16 |
||
792 | jnc .end_b |
||
793 | mov dword[ob1],0xff00 |
||
794 | .end_b: |
||
795 | end if |
||
5175 | IgorA | 796 | PUT_PIXEL 0 |
5153 | IgorA | 797 | if INTERP_Z eq 1 |
6126 | IgorA | 798 | add esi,2 ;=sizeof(uint) |
5153 | IgorA | 799 | end if |
5175 | IgorA | 800 | add edi,PSZB |
801 | dec dword[n] |
||
5187 | IgorA | 802 | jmp .cycle_2 |
803 | .cycle_2_end: |
||
804 | end if ;проверка от макроса DRAW_LINE |
||
5175 | IgorA | 805 | |
806 | ; left edge |
||
807 | mov eax,[derror] |
||
808 | add [error],eax |
||
5187 | IgorA | 809 | cmp dword[error],0 ;if (error > 0) |
5175 | IgorA | 810 | jle .els_er |
811 | sub dword[error],0x10000 |
||
812 | mov eax,[dxdy_max] |
||
813 | add [x1],eax |
||
5153 | IgorA | 814 | if INTERP_Z eq 1 |
5175 | IgorA | 815 | mov eax,[dzdl_max] |
816 | add [z1],eax |
||
5153 | IgorA | 817 | end if |
818 | if INTERP_RGB eq 1 |
||
5175 | IgorA | 819 | mov eax,[drdl_max] |
820 | add [r1],eax |
||
821 | mov eax,[dgdl_max] |
||
822 | add [g1],eax |
||
823 | mov eax,[dbdl_max] |
||
824 | add [b1],eax |
||
5153 | IgorA | 825 | end if |
826 | if INTERP_ST eq 1 |
||
5175 | IgorA | 827 | mov eax,[dsdl_max] |
828 | add [s1],eax |
||
829 | mov eax,[dtdl_max] |
||
830 | add [t1],eax |
||
5153 | IgorA | 831 | end if |
832 | if INTERP_STZ eq 1 |
||
5175 | IgorA | 833 | fld dword[dszdl_max] |
834 | fadd dword[sz1] |
||
835 | fstp dword[sz1] |
||
836 | fld dword[dtzdl_max] |
||
837 | fadd dword[tz1] |
||
838 | fstp dword[tz1] |
||
5153 | IgorA | 839 | end if |
5175 | IgorA | 840 | jmp .end_er |
841 | .els_er: |
||
842 | mov eax,[dxdy_min] |
||
843 | add [x1],eax |
||
5153 | IgorA | 844 | if INTERP_Z eq 1 |
5175 | IgorA | 845 | mov eax,[dzdl_min] |
846 | add [z1],eax |
||
5153 | IgorA | 847 | end if |
848 | if INTERP_RGB eq 1 |
||
5175 | IgorA | 849 | mov eax,[drdl_min] |
850 | add [r1],eax |
||
851 | mov eax,[dgdl_min] |
||
852 | add [g1],eax |
||
853 | mov eax,[dbdl_min] |
||
854 | add [b1],eax |
||
5153 | IgorA | 855 | end if |
856 | if INTERP_ST eq 1 |
||
5175 | IgorA | 857 | mov eax,[dsdl_min] |
858 | add [s1],eax |
||
859 | mov eax,[dtdl_min] |
||
860 | add [t1],eax |
||
5153 | IgorA | 861 | end if |
862 | if INTERP_STZ eq 1 |
||
5175 | IgorA | 863 | fld dword[dszdl_min] |
864 | fadd dword[sz1] |
||
865 | fstp dword[sz1] |
||
866 | fld dword[dtzdl_min] |
||
867 | fadd dword[tz1] |
||
868 | fstp dword[tz1] |
||
5153 | IgorA | 869 | end if |
5175 | IgorA | 870 | .end_er: |
871 | ; right edge |
||
872 | mov eax,[dx2dy2] |
||
873 | add [x2],eax |
||
874 | |||
875 | ; screen coordinates |
||
876 | mov ebx,[zb] |
||
877 | mov eax,[ebx+offs_zbuf_linesize] |
||
878 | add [pp1],eax |
||
879 | mov eax,[ebx+offs_zbuf_xsize] |
||
880 | shl eax,1 |
||
881 | add [pz1],eax |
||
882 | jmp .beg_w_lin |
||
883 | .end_w_lin: |
||
884 | inc dword[part] |
||
885 | cmp dword[part],2 |
||
886 | jl .cycle_0 |
||
887 | .end_f: |
||
5187 | IgorA | 888 | popad |
5175 | IgorA | 889 | ret |
890 | endp |
||
891 | |||
5153 | IgorA | 892 | restore INTERP_Z |
893 | restore INTERP_RGB |
||
894 | restore INTERP_ST |
||
895 | restore INTERP_STZ |
||
5175 | IgorA | 896 | restore DRAW_LINE_M |
5153 | IgorA | 897 | |
898 | purge DRAW_INIT |
||
5175 | IgorA | 899 | purge DRAW_LINE |
5153 | IgorA | 900 | purge PUT_PIXEL><>><>><>><>><>> |