Rev 9237 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
9237 | leency | 1 | ROUND equ 8 |
2 | CATMULL_SHIFT equ 8 |
||
3 | gouraud_triangle_z: |
||
4 | |||
5 | ;----procedure drawing gouraud triangle with z coordinate |
||
6 | ;----interpolation ( Catmull alghoritm )----------------- |
||
7 | ;------------------in - eax - x1 shl 16 + y1 ------------ |
||
8 | ;---------------------- ebx - x2 shl 16 + y2 ------------ |
||
9 | ;---------------------- ecx - x3 shl 16 + y3 ------------ |
||
10 | ;---------------------- esi - pointer to Z-buffer-------- |
||
11 | ;---------------------- Z-buffer filled with dd variables |
||
12 | ;---------------------- shifted CATMULL_SHIFT------------ |
||
13 | ;---------------------- edi - pointer to screen buffer--- |
||
14 | ;---------------------- stack : colors------------------- |
||
15 | ;----------------- procedure don't save registers !!----- |
||
16 | .col1r equ ebp+4 ; each color as word |
||
17 | .col1g equ ebp+6 ; each z coordinate as word |
||
18 | .col1b equ ebp+8 |
||
19 | .z1 equ ebp+10 |
||
20 | .col2r equ ebp+12 |
||
21 | .col2g equ ebp+14 |
||
22 | .col2b equ ebp+16 |
||
23 | .z2 equ ebp+18 |
||
24 | .col3r equ ebp+20 |
||
25 | .col3g equ ebp+22 |
||
26 | .col3b equ ebp+24 |
||
27 | .z3 equ ebp+26 |
||
28 | |||
29 | .x1 equ word[ebp-2] |
||
30 | .y1 equ word[ebp-4] |
||
31 | .x2 equ word[ebp-6] |
||
32 | .y2 equ word[ebp-8] |
||
33 | .x3 equ word[ebp-10] |
||
34 | .y3 equ word[ebp-12] |
||
35 | |||
36 | .dx12 equ dword[ebp-16] |
||
37 | .dz12 equ dword[ebp-20] |
||
38 | .dc12r equ dword[ebp-24] |
||
39 | .dc12g equ dword[ebp-28] |
||
9740 | macgub | 40 | .dc12b equ [ebp-32] |
9237 | leency | 41 | |
42 | .dx13 equ dword[ebp-36] |
||
43 | .dz13 equ dword[ebp-40] |
||
44 | .dc13r equ dword[ebp-44] |
||
45 | .dc13g equ dword[ebp-48] |
||
9740 | macgub | 46 | .dc13b equ [ebp-52] |
9237 | leency | 47 | |
48 | .dx23 equ dword[ebp-56] |
||
49 | .dz23 equ dword[ebp-60] |
||
50 | .dc23r equ dword[ebp-64] |
||
51 | .dc23g equ dword[ebp-68] |
||
9740 | macgub | 52 | .dc23b equ [ebp-72] |
9237 | leency | 53 | |
54 | .zz1 equ dword[ebp-76] |
||
55 | .c1r equ dword[ebp-80] |
||
56 | .c1g equ dword[ebp-84] |
||
57 | .c1b equ dword[ebp-88] |
||
58 | .zz2 equ dword[ebp-92] |
||
59 | .c2r equ dword[ebp-96] |
||
60 | .c2g equ dword[ebp-100] |
||
61 | .c2b equ dword[ebp-104] |
||
62 | ;.zz1 equ dword[ebp-100] |
||
63 | ;.zz2 equ dword[ebp-104] |
||
64 | |||
65 | .c1bM equ [ebp-88] |
||
66 | .c2bM equ [ebp-104] |
||
67 | .c1rM equ [ebp-80] |
||
68 | .c2rM equ [ebp-96] |
||
69 | .dc23bM equ [ebp-72] |
||
70 | .dc13bM equ [ebp-52] |
||
71 | .dc12bM equ [ebp-32] |
||
72 | .dc12rM equ [ebp-24] |
||
73 | .dc13rM equ [ebp-44] |
||
74 | .dc23rM equ [ebp-64] |
||
75 | if Ext=MMX |
||
76 | emms |
||
77 | end if |
||
78 | |||
79 | mov ebp,esp |
||
80 | ; sub esp,84 |
||
9740 | macgub | 81 | .sort3: ; sort triangle coordinates... |
9237 | leency | 82 | cmp ax,bx |
83 | jle .sort1 |
||
84 | xchg eax,ebx |
||
85 | mov edx,dword[.col1r] |
||
86 | xchg edx,dword[.col2r] |
||
87 | mov dword[.col1r],edx |
||
88 | mov edx,dword[.col1b] |
||
89 | xchg edx,dword[.col2b] |
||
90 | mov dword[.col1b],edx |
||
91 | .sort1: |
||
9740 | macgub | 92 | cmp bx,cx |
93 | jle .sort2 |
||
94 | xchg ebx,ecx |
||
95 | mov edx,dword[.col2r] |
||
96 | xchg edx,dword[.col3r] |
||
97 | mov dword[.col2r],edx |
||
98 | mov edx,dword[.col2b] |
||
99 | xchg edx,dword[.col3b] |
||
100 | mov dword[.col2b],edx |
||
9237 | leency | 101 | jmp .sort3 |
102 | .sort2: |
||
9740 | macgub | 103 | push eax ; store in variables |
104 | push ebx |
||
105 | push ecx |
||
106 | mov edx,80008000h ; eax,ebx,ecx are ANDd together into edx which means that |
||
107 | and edx,ebx ; if *all* of them are negative a sign flag is raised |
||
108 | and edx,ecx |
||
109 | and edx,eax |
||
110 | test edx,80008000h ; Check both X&Y at once |
||
111 | jne .gt_loop2_end |
||
9237 | leency | 112 | |
9740 | macgub | 113 | mov bx,.y2 ; calc deltas |
114 | sub bx,.y1 |
||
115 | jnz .gt_dx12_make |
||
9237 | leency | 116 | ; mov .dx12,0 |
117 | ; mov .dz12,0 |
||
118 | ; mov .dc12r,0 |
||
119 | ; mov .dc12g,0 |
||
120 | ; mov .dc12b,0 |
||
9740 | macgub | 121 | mov ecx,5 |
9237 | leency | 122 | @@: |
9740 | macgub | 123 | push dword 0 |
124 | loop @b |
||
125 | jmp .gt_dx12_done |
||
9237 | leency | 126 | .gt_dx12_make: |
9740 | macgub | 127 | |
128 | if Ext>= SSE2 |
||
129 | |||
130 | movsx ebx,bx |
||
131 | mov eax,1 shl 15 |
||
132 | cdq |
||
133 | idiv ebx |
||
134 | ; push eax |
||
135 | mov ebx,eax |
||
136 | |||
137 | |||
138 | mov ax,.x2 |
||
139 | sub ax,.x1 |
||
9237 | leency | 140 | cwde |
9740 | macgub | 141 | imul ebx |
142 | sar eax,15 - ROUND |
||
143 | push eax |
||
144 | ; mov .dx12,eax |
||
145 | |||
146 | sub esp,4*4 |
||
147 | movd xmm0,ebx |
||
148 | pshuflw xmm0,xmm0,0 |
||
149 | movq xmm1,[.col1r] |
||
150 | movq xmm2,[.col2r] |
||
151 | psubw xmm2,xmm1 |
||
152 | movdqa xmm3,xmm2 |
||
153 | pmullw xmm2,xmm0 |
||
154 | pmulhw xmm3,xmm0 |
||
155 | punpcklwd xmm2,xmm3 |
||
156 | psrad xmm2,15 - ROUND |
||
157 | pshufd xmm2,xmm2,11000110b |
||
158 | movdqu .dc12b,xmm2 |
||
159 | else |
||
160 | mov ax,.x2 |
||
161 | sub ax,.x1 |
||
162 | cwde |
||
163 | movsx ebx,bx |
||
164 | shl eax,ROUND |
||
9237 | leency | 165 | cdq |
9740 | macgub | 166 | idiv ebx |
9237 | leency | 167 | ; mov .dx12,eax |
9740 | macgub | 168 | push eax |
9237 | leency | 169 | |
9740 | macgub | 170 | mov ax,word[.z2] |
171 | sub ax,word[.z1] |
||
9237 | leency | 172 | cwde |
9740 | macgub | 173 | shl eax,CATMULL_SHIFT |
9237 | leency | 174 | cdq |
9740 | macgub | 175 | idiv ebx |
176 | push eax |
||
9237 | leency | 177 | |
9740 | macgub | 178 | mov ax,word[.col2r] |
179 | sub ax,word[.col1r] |
||
9237 | leency | 180 | cwde |
9740 | macgub | 181 | shl eax,ROUND |
9237 | leency | 182 | cdq |
9740 | macgub | 183 | idiv ebx |
9237 | leency | 184 | ; mov .dc12r,eax |
9740 | macgub | 185 | push eax |
186 | mov ax,word[.col2g] |
||
187 | sub ax,word[.col1g] |
||
9237 | leency | 188 | cwde |
9740 | macgub | 189 | shl eax,ROUND |
9237 | leency | 190 | cdq |
9740 | macgub | 191 | idiv ebx |
9237 | leency | 192 | ; mov .dc12g,eax |
9740 | macgub | 193 | push eax |
194 | mov ax,word[.col2b] ;;--- |
||
195 | sub ax,word[.col1b] |
||
9237 | leency | 196 | cwde |
9740 | macgub | 197 | shl eax,ROUND |
9237 | leency | 198 | cdq |
9740 | macgub | 199 | idiv ebx |
9237 | leency | 200 | ; mov .dc12b,eax |
9740 | macgub | 201 | push eax |
202 | end if |
||
9237 | leency | 203 | .gt_dx12_done: |
204 | |||
9740 | macgub | 205 | mov bx,.y3 ; calc deltas |
206 | sub bx,.y1 |
||
207 | jnz .gt_dx13_make |
||
9237 | leency | 208 | ; mov .dx13,0 |
209 | ; mov .dz13,0 |
||
210 | ; mov .dc13r,0 |
||
211 | ; mov .dc13g,0 |
||
212 | ; mov .dc13b,0 |
||
9740 | macgub | 213 | mov ecx,5 |
9237 | leency | 214 | @@: |
9740 | macgub | 215 | push dword 0 |
216 | loop @b |
||
217 | jmp .gt_dx13_done |
||
9237 | leency | 218 | .gt_dx13_make: |
9740 | macgub | 219 | |
220 | if Ext>= SSE2 |
||
221 | |||
222 | movsx ebx,bx |
||
223 | mov eax,1 shl 15 |
||
224 | cdq |
||
225 | idiv ebx |
||
226 | mov ebx,eax |
||
227 | |||
228 | |||
229 | mov ax,.x3 |
||
230 | sub ax,.x1 |
||
9237 | leency | 231 | cwde |
9740 | macgub | 232 | imul ebx |
233 | sar eax,15 - ROUND |
||
234 | push eax |
||
235 | |||
236 | sub esp,4*4 |
||
237 | movd xmm0,ebx |
||
238 | pshuflw xmm0,xmm0,0 |
||
239 | movq xmm1,[.col1r] |
||
240 | movq xmm2,[.col3r] |
||
241 | psubw xmm2,xmm1 |
||
242 | movdqa xmm3,xmm2 |
||
243 | pmullw xmm2,xmm0 |
||
244 | pmulhw xmm3,xmm0 |
||
245 | punpcklwd xmm2,xmm3 |
||
246 | psrad xmm2,15 - ROUND |
||
247 | pshufd xmm2,xmm2,11000110b |
||
248 | movdqu .dc13b,xmm2 |
||
249 | else |
||
250 | |||
251 | mov ax,.x3 |
||
252 | sub ax,.x1 |
||
253 | cwde |
||
254 | movsx ebx,bx |
||
255 | shl eax,ROUND |
||
9237 | leency | 256 | cdq |
9740 | macgub | 257 | idiv ebx |
9237 | leency | 258 | ; mov .dx13,eax |
9740 | macgub | 259 | push eax |
9237 | leency | 260 | |
9740 | macgub | 261 | mov ax,word[.z3] |
262 | sub ax,word[.z1] |
||
9237 | leency | 263 | cwde |
9740 | macgub | 264 | shl eax,CATMULL_SHIFT |
9237 | leency | 265 | cdq |
9740 | macgub | 266 | idiv ebx |
267 | push eax |
||
9237 | leency | 268 | |
9740 | macgub | 269 | mov ax,word[.col3r] |
270 | sub ax,word[.col1r] |
||
9237 | leency | 271 | cwde |
9740 | macgub | 272 | shl eax,ROUND |
9237 | leency | 273 | cdq |
9740 | macgub | 274 | idiv ebx |
9237 | leency | 275 | ; mov .dc13r,eax |
9740 | macgub | 276 | push eax |
277 | mov ax,word[.col3g] |
||
278 | sub ax,word[.col1g] |
||
9237 | leency | 279 | cwde |
9740 | macgub | 280 | shl eax,ROUND |
9237 | leency | 281 | cdq |
9740 | macgub | 282 | idiv ebx |
9237 | leency | 283 | ; mov .dc13g,eax |
9740 | macgub | 284 | push eax |
285 | mov ax,word[.col3b] |
||
286 | sub ax,word[.col1b] |
||
9237 | leency | 287 | cwde |
9740 | macgub | 288 | shl eax,ROUND |
9237 | leency | 289 | cdq |
9740 | macgub | 290 | idiv ebx |
9237 | leency | 291 | ; mov .dc13b,eax |
9740 | macgub | 292 | push eax |
293 | end if |
||
9237 | leency | 294 | .gt_dx13_done: |
295 | |||
9740 | macgub | 296 | mov bx,.y3 ; calc deltas |
297 | sub bx,.y2 |
||
298 | jnz .gt_dx23_make |
||
9237 | leency | 299 | ; mov .dx23,0 |
300 | ; mov .dz23,0 |
||
301 | ; mov .dc23r,0 |
||
302 | ; mov .dc23g,0 |
||
303 | ; mov .dc23b,0 |
||
9740 | macgub | 304 | mov ecx,5 |
9237 | leency | 305 | @@: |
9740 | macgub | 306 | push dword 0 |
307 | loop @b |
||
308 | jmp .gt_dx23_done |
||
9237 | leency | 309 | .gt_dx23_make: |
9740 | macgub | 310 | |
311 | if Ext>= SSE2 |
||
312 | |||
313 | movsx ebx,bx |
||
314 | mov eax,1 shl 15 |
||
315 | cdq |
||
316 | idiv ebx |
||
317 | ; push eax |
||
318 | mov ebx,eax |
||
319 | |||
320 | mov ax,.x3 |
||
321 | sub ax,.x2 |
||
9237 | leency | 322 | cwde |
9740 | macgub | 323 | imul ebx |
324 | sar eax,15 - ROUND |
||
325 | push eax |
||
326 | |||
327 | sub esp,4*4 |
||
328 | movd xmm0,ebx |
||
329 | pshuflw xmm0,xmm0,0 |
||
330 | movq xmm1,[.col2r] |
||
331 | movq xmm2,[.col3r] |
||
332 | psubw xmm2,xmm1 |
||
333 | movdqa xmm3,xmm2 |
||
334 | pmullw xmm2,xmm0 |
||
335 | pmulhw xmm3,xmm0 |
||
336 | punpcklwd xmm2,xmm3 |
||
337 | psrad xmm2,15 - ROUND |
||
338 | pshufd xmm2,xmm2,11000110b |
||
339 | movdqu .dc23b,xmm2 |
||
340 | else |
||
341 | |||
342 | |||
343 | mov ax,.x3 |
||
344 | sub ax,.x2 |
||
345 | cwde |
||
346 | movsx ebx,bx |
||
347 | shl eax,ROUND |
||
9237 | leency | 348 | cdq |
9740 | macgub | 349 | idiv ebx |
9237 | leency | 350 | ; mov .dx23,eax |
9740 | macgub | 351 | push eax |
9237 | leency | 352 | |
9740 | macgub | 353 | mov ax,word[.z3] |
354 | sub ax,word[.z2] |
||
9237 | leency | 355 | cwde |
9740 | macgub | 356 | shl eax,CATMULL_SHIFT |
9237 | leency | 357 | cdq |
9740 | macgub | 358 | idiv ebx |
359 | push eax |
||
9237 | leency | 360 | |
9740 | macgub | 361 | mov ax,word[.col3r] |
362 | sub ax,word[.col2r] |
||
9237 | leency | 363 | cwde |
9740 | macgub | 364 | shl eax,ROUND |
9237 | leency | 365 | cdq |
9740 | macgub | 366 | idiv ebx |
9237 | leency | 367 | ; mov .dc23r,eax |
9740 | macgub | 368 | push eax |
369 | mov ax,word[.col3g] |
||
370 | sub ax,word[.col2g] |
||
9237 | leency | 371 | cwde |
9740 | macgub | 372 | shl eax,ROUND |
9237 | leency | 373 | cdq |
9740 | macgub | 374 | idiv ebx |
9237 | leency | 375 | ; mov .dc23g,eax |
9740 | macgub | 376 | push eax |
377 | mov ax,word[.col3b] |
||
378 | sub ax,word[.col2b] |
||
9237 | leency | 379 | cwde |
9740 | macgub | 380 | shl eax,ROUND |
9237 | leency | 381 | cdq |
9740 | macgub | 382 | idiv ebx |
9237 | leency | 383 | ; mov .dc23b,eax |
9740 | macgub | 384 | push eax |
385 | end if |
||
9237 | leency | 386 | .gt_dx23_done: |
9740 | macgub | 387 | sub esp,32 |
9237 | leency | 388 | |
9740 | macgub | 389 | movsx eax,.x1 ; eax - cur x1 |
390 | shl eax,ROUND ; ebx - cur x2 |
||
391 | mov ebx,eax |
||
392 | movsx edx,word[.z1] |
||
393 | shl edx,CATMULL_SHIFT |
||
394 | mov .zz1,edx |
||
395 | mov .zz2,edx |
||
396 | movzx edx,word[.col1r] |
||
397 | shl edx,ROUND |
||
398 | mov .c1r,edx |
||
399 | mov .c2r,edx |
||
400 | movzx edx,word[.col1g] |
||
401 | shl edx,ROUND |
||
402 | mov .c1g,edx |
||
403 | mov .c2g,edx |
||
404 | movzx edx,word[.col1b] |
||
405 | shl edx,ROUND |
||
406 | mov .c1b,edx |
||
407 | mov .c2b,edx |
||
408 | mov cx,.y1 |
||
409 | cmp cx,.y2 |
||
410 | jge .gt_loop1_end |
||
9237 | leency | 411 | |
412 | .gt_loop1: |
||
413 | pushad |
||
414 | ; macro .debug |
||
415 | |||
9740 | macgub | 416 | mov edx,.c2r ; c2r,c2g,c2b,c1r,c1g,c1b - current colors |
417 | sar edx,ROUND |
||
418 | push dx |
||
419 | mov edx,.c2g |
||
420 | sar edx,ROUND |
||
421 | push dx |
||
422 | mov edx,.c2b |
||
423 | sar edx,ROUND |
||
424 | push dx |
||
425 | sar ebx,ROUND ; x2 |
||
426 | push bx |
||
427 | mov edx,.c1r |
||
428 | sar edx,ROUND |
||
429 | push dx |
||
430 | mov edx,.c1g |
||
431 | sar edx,ROUND |
||
432 | push dx |
||
433 | mov edx,.c1b |
||
434 | sar edx,ROUND |
||
435 | push dx |
||
436 | sar eax,ROUND |
||
437 | push ax ; x1 |
||
438 | push cx ; y |
||
439 | push .zz2 |
||
440 | push .zz1 |
||
441 | call gouraud_line_z |
||
9237 | leency | 442 | |
443 | popad |
||
9740 | macgub | 444 | |
9237 | leency | 445 | if Ext >= MMX |
9740 | macgub | 446 | movq mm0,.c1bM |
447 | paddd mm0,qword .dc13bM |
||
448 | movq .c1bM,mm0 |
||
449 | movq mm1,.c2bM |
||
450 | paddd mm1,qword .dc12bM |
||
451 | movq .c2bM,mm1 |
||
9237 | leency | 452 | |
9740 | macgub | 453 | movq mm0,.c1rM |
454 | paddd mm0,qword .dc13rM |
||
455 | movq .c1rM,mm0 |
||
456 | movq mm1,.c2rM |
||
457 | paddd mm1,qword .dc12rM |
||
458 | movq .c2rM,mm1 |
||
9237 | leency | 459 | else |
9740 | macgub | 460 | mov edx,.dc13r |
461 | add .c1r,edx |
||
462 | mov edx,.dc13g |
||
463 | add .c1g,edx |
||
464 | mov edx,.dc13b |
||
465 | add .c1b,edx |
||
466 | mov edx,.dc12r |
||
467 | add .c2r,edx |
||
468 | mov edx,.dc12g |
||
469 | add .c2g,edx |
||
470 | mov edx,.dc12b |
||
471 | add .c2b,edx |
||
9237 | leency | 472 | |
9740 | macgub | 473 | mov edx,.dz13 |
474 | add .zz1,edx |
||
475 | mov edx,.dz12 |
||
476 | add .zz2,edx |
||
9237 | leency | 477 | end if |
9740 | macgub | 478 | add eax,.dx13 |
479 | add ebx,.dx12 |
||
480 | inc cx |
||
481 | cmp cx,.y2 |
||
482 | jl .gt_loop1 |
||
9237 | leency | 483 | |
484 | .gt_loop1_end: |
||
9740 | macgub | 485 | mov cx,.y2 |
486 | cmp cx,.y3 |
||
487 | jge .gt_loop2_end |
||
9237 | leency | 488 | |
9740 | macgub | 489 | movsx ebx,.x2 ; eax - cur x1 |
490 | shl ebx,ROUND ; ebx - cur x2 |
||
491 | movsx edx,word[.z2] |
||
492 | shl edx,CATMULL_SHIFT |
||
493 | mov .zz2,edx |
||
494 | movzx edx,word[.col2r] |
||
495 | shl edx,ROUND |
||
496 | mov .c2r,edx |
||
497 | movzx edx,word[.col2g] |
||
498 | shl edx,ROUND |
||
499 | mov .c2g,edx |
||
500 | movzx edx,word[.col2b] |
||
501 | shl edx,ROUND |
||
502 | mov .c2b,edx |
||
9237 | leency | 503 | |
504 | .gt_loop2: |
||
505 | pushad |
||
506 | ; macro .debug |
||
507 | |||
9740 | macgub | 508 | mov edx,.c2r ; c2r,c2g,c2b,c1r,c1g,c1b - current colors |
509 | sar edx,ROUND |
||
510 | push dx |
||
511 | mov edx,.c2g |
||
512 | sar edx,ROUND |
||
513 | push dx |
||
514 | mov edx,.c2b |
||
515 | sar edx,ROUND |
||
516 | push dx |
||
517 | sar ebx,ROUND ; x2 |
||
518 | push bx |
||
519 | mov edx,.c1r |
||
520 | sar edx,ROUND |
||
521 | push dx |
||
522 | mov edx,.c1g |
||
523 | sar edx,ROUND |
||
524 | push dx |
||
525 | mov edx,.c1b |
||
526 | sar edx,ROUND |
||
527 | push dx |
||
528 | sar eax,ROUND |
||
529 | push ax ; x1 |
||
530 | push cx ; y |
||
531 | push .zz2 |
||
532 | push .zz1 |
||
533 | call gouraud_line_z |
||
9237 | leency | 534 | |
535 | popad |
||
536 | |||
537 | if Ext >= MMX |
||
9740 | macgub | 538 | movq mm0,.c1bM |
539 | paddd mm0,qword .dc13bM |
||
540 | movq .c1bM,mm0 |
||
541 | movq mm1,.c2bM |
||
542 | paddd mm1,qword .dc23bM |
||
543 | movq .c2bM,mm1 |
||
9237 | leency | 544 | |
9740 | macgub | 545 | movq mm0,.c1rM |
546 | paddd mm0,qword .dc13rM |
||
547 | movq .c1rM,mm0 |
||
548 | movq mm1,.c2rM |
||
549 | paddd mm1,qword .dc23rM |
||
550 | movq .c2rM,mm1 |
||
9237 | leency | 551 | else |
9740 | macgub | 552 | mov edx,.dc13r |
553 | add .c1r,edx |
||
554 | mov edx,.dc13g |
||
555 | add .c1g,edx |
||
556 | mov edx,.dc13b |
||
557 | add .c1b,edx |
||
558 | mov edx,.dc23r |
||
559 | add .c2r,edx |
||
560 | mov edx,.dc23g |
||
561 | add .c2g,edx |
||
562 | mov edx,.dc23b |
||
563 | add .c2b,edx |
||
564 | mov edx,.dz13 |
||
565 | add .zz1,edx |
||
566 | mov edx,.dz23 |
||
567 | add .zz2,edx |
||
9237 | leency | 568 | end if |
9740 | macgub | 569 | add eax,.dx13 |
570 | add ebx,.dx23 |
||
571 | inc cx |
||
572 | cmp cx,.y3 |
||
573 | jl .gt_loop2 |
||
9237 | leency | 574 | .gt_loop2_end: |
575 | |||
9740 | macgub | 576 | mov esp,ebp |
9237 | leency | 577 | ret 24 |
578 | gouraud_line_z: |
||
579 | ;----------------- procedure drawing gouraud line |
||
580 | ;----------------- with z coordinate interpolation |
||
581 | ;----------------- esi - pointer to Z_buffer |
||
582 | ;----------------- edi - pointer to screen buffer |
||
583 | ;----------------- stack: |
||
9740 | macgub | 584 | .z1 equ dword[ebp+4] ; z coordiunate shifted left CATMULL_SHIFT |
9237 | leency | 585 | .z2 equ dword[ebp+8] |
586 | .y equ word[ebp+12] |
||
587 | .x1 equ ebp+14 |
||
9740 | macgub | 588 | |
9237 | leency | 589 | .c1b equ ebp+16 |
590 | .c1g equ ebp+18 |
||
591 | .c1r equ ebp+20 |
||
592 | .x2 equ ebp+22 |
||
593 | .c2b equ ebp+24 |
||
594 | .c2g equ ebp+26 |
||
595 | .c2r equ ebp+28 |
||
596 | |||
597 | .dz equ dword[ebp-4] |
||
598 | .dc_b equ dword[ebp-8] |
||
599 | .dc_g equ dword[ebp-12] |
||
600 | .dc_r equ dword[ebp-16] |
||
601 | .c_z equ dword[ebp-20] |
||
602 | .cb equ dword[ebp-24] |
||
603 | .cg equ dword[ebp-28] |
||
604 | .cr equ dword[ebp-32] |
||
605 | ;.cg2 equ dword[ebp-36] |
||
606 | |||
607 | |||
608 | .crM equ ebp-32 |
||
609 | .cgM equ ebp-28 |
||
610 | .cbM equ ebp-24 |
||
611 | |||
612 | .dc_rM equ ebp-16 |
||
613 | .dc_gM equ ebp-12 |
||
614 | .dc_bM equ ebp-8 |
||
9740 | macgub | 615 | mov ebp,esp |
9237 | leency | 616 | |
9740 | macgub | 617 | mov ax,.y |
618 | or ax,ax |
||
619 | jl .gl_quit |
||
620 | mov bx,[size_y_var] |
||
621 | dec bx |
||
622 | cmp ax,bx ;SIZE_Y |
||
623 | jge .gl_quit |
||
9237 | leency | 624 | |
9740 | macgub | 625 | mov eax,dword[.x1] |
626 | cmp ax,word[.x2] |
||
627 | je .gl_quit |
||
628 | jl @f |
||
9237 | leency | 629 | |
9740 | macgub | 630 | xchg eax,dword[.x2] |
631 | mov dword[.x1],eax |
||
632 | mov eax,dword[.c1g] |
||
633 | xchg eax,dword[.c2g] |
||
634 | mov dword[.c1g],eax |
||
635 | mov eax,.z1 |
||
636 | xchg eax,.z2 |
||
637 | mov .z1,eax |
||
9237 | leency | 638 | @@: |
9740 | macgub | 639 | mov bx,[size_x_var] |
640 | dec bx |
||
641 | cmp word[.x1],bx ;SIZE_X |
||
642 | jge .gl_quit |
||
643 | cmp word[.x2],0 |
||
644 | jle .gl_quit |
||
9237 | leency | 645 | |
9740 | macgub | 646 | if 0 |
647 | mov bx,word[.x2] ; dz = z2-z1/x2-x1 |
||
648 | sub bx,word[.x1] |
||
649 | movsx ebx,bx |
||
9237 | leency | 650 | |
651 | |||
9740 | macgub | 652 | mov eax,1 shl 15 |
653 | cdq |
||
654 | idiv ebx |
||
655 | mov ebx,eax |
||
9237 | leency | 656 | |
657 | |||
9740 | macgub | 658 | mov eax,.x3 |
659 | sub eax,.x1 |
||
660 | cwde |
||
661 | imul ebx |
||
662 | sar eax,15 - ROUND |
||
663 | push eax |
||
9237 | leency | 664 | |
9740 | macgub | 665 | sub esp,4*4 |
666 | movd xmm0,ebx |
||
667 | pshuflw xmm0,xmm0,0 |
||
668 | movq xmm1,[.col1r] |
||
669 | movq xmm2,[.col3r] |
||
670 | psubw xmm2,xmm1 |
||
671 | movdqa xmm3,xmm2 |
||
672 | pmullw xmm2,xmm0 |
||
673 | pmulhw xmm3,xmm0 |
||
674 | punpcklwd xmm2,xmm3 |
||
675 | psrad xmm2,15 - ROUND |
||
676 | pshufd xmm2,xmm2,11000110b |
||
677 | movdqu .dc13b,xmm2 |
||
9237 | leency | 678 | |
679 | |||
9740 | macgub | 680 | end if |
9237 | leency | 681 | |
9740 | macgub | 682 | |
683 | mov eax,.z2 |
||
684 | sub eax,.z1 |
||
685 | cdq |
||
686 | mov bx,word[.x2] ; dz = z2-z1/x2-x1 |
||
687 | sub bx,word[.x1] |
||
688 | movsx ebx,bx |
||
689 | idiv ebx |
||
690 | push eax |
||
691 | |||
692 | |||
693 | mov eax,1 shl 15 |
||
694 | cdq |
||
695 | idiv ebx |
||
696 | mov ebx,eax |
||
697 | |||
698 | |||
699 | mov ax,word[.c2b] |
||
700 | sub ax,word[.c1b] |
||
701 | cwde |
||
702 | imul ebx |
||
703 | sar eax,15 - ROUND |
||
704 | push eax |
||
705 | |||
706 | |||
707 | mov ax,word[.c2g] |
||
708 | sub ax,word[.c1g] |
||
709 | cwde |
||
710 | imul ebx |
||
711 | sar eax,15 - ROUND |
||
712 | push eax |
||
713 | |||
714 | |||
715 | |||
716 | mov ax,word[.c2r] |
||
717 | sub ax,word[.c1r] |
||
718 | cwde |
||
719 | imul ebx |
||
720 | sar eax,15 - ROUND |
||
721 | push eax |
||
722 | |||
723 | cmp word[.x1],0 ; clipping on function |
||
724 | jg @f |
||
725 | mov eax,.dz |
||
726 | movsx ebx,word[.x1] |
||
727 | neg ebx |
||
728 | imul ebx |
||
729 | add .z1,eax |
||
730 | mov word[.x1],0 |
||
731 | |||
732 | mov eax,.dc_r |
||
733 | imul ebx |
||
734 | sar eax,ROUND |
||
735 | add word[.c1r],ax |
||
736 | |||
737 | mov eax,.dc_g |
||
738 | imul ebx |
||
739 | sar eax,ROUND |
||
740 | add word[.c1g],ax |
||
741 | |||
742 | mov eax,.dc_b |
||
743 | imul ebx |
||
744 | sar eax,ROUND |
||
745 | add word[.c1b],ax |
||
746 | |||
9237 | leency | 747 | @@: |
9740 | macgub | 748 | mov bx,[size_x_var] |
749 | dec bx |
||
750 | cmp word[.x2],bx ;SIZE_X |
||
751 | jl @f |
||
752 | mov word[.x2],bx ;SIZE_X |
||
9237 | leency | 753 | @@: |
9740 | macgub | 754 | sub esp,16 ; calculate memory begin |
755 | movzx edx,word[size_x_var] ;SIZE_X ; in buffers |
||
756 | movzx eax,.y |
||
757 | mul edx |
||
758 | movzx edx,word[.x1] |
||
759 | add eax,edx |
||
760 | push eax |
||
761 | lea eax,[eax*3] |
||
762 | add edi,eax |
||
763 | pop eax |
||
764 | shl eax,2 |
||
765 | add esi,eax |
||
9237 | leency | 766 | |
9740 | macgub | 767 | mov cx,word[.x2] |
768 | sub cx,word[.x1] |
||
769 | movzx ecx,cx |
||
770 | mov ebx,.z1 ; ebx - currrent z shl CATMULL_SIFT |
||
9237 | leency | 771 | ;if Ext >= SSE |
772 | ; mov .cz,edx |
||
773 | ;end if |
||
9740 | macgub | 774 | mov edx,.dz ; edx - delta z |
775 | if Ext >= SSE2 |
||
776 | movq xmm7,[.c1b] |
||
777 | pshuflw xmm7,xmm7,11000110b |
||
778 | punpcklwd xmm7,[the_zero] |
||
779 | pslld xmm7,ROUND |
||
780 | movdqu xmm1,[.dc_rM] |
||
781 | end if |
||
782 | if Ext = NON |
||
783 | movzx eax,word[.c1r] |
||
784 | shl eax,ROUND |
||
785 | mov .cr,eax |
||
786 | movzx eax,word[.c1g] |
||
787 | shl eax,ROUND |
||
788 | mov .cg,eax |
||
789 | movzx eax,word[.c1b] |
||
790 | shl eax,ROUND |
||
791 | mov .cb,eax |
||
792 | end if |
||
793 | if (Ext = MMX) | (Ext=SSE) |
||
9237 | leency | 794 | ; mov .c_z,edx |
9740 | macgub | 795 | movd mm2,[.dc_bM] ; delta color blue MMX |
796 | movd mm3,[.cbM] ; current blue MMX |
||
797 | movq mm5,[.dc_rM] |
||
798 | movq mm4,[.crM] |
||
799 | pxor mm6,mm6 |
||
9237 | leency | 800 | end if |
801 | |||
802 | |||
803 | .ddraw: |
||
804 | ;if Ext = MMX |
||
805 | ; movq mm0,mm3 |
||
806 | ; psrsq mm0,32 |
||
807 | ; movd ebx,mm0 |
||
808 | ;end if |
||
9740 | macgub | 809 | cmp ebx,dword[esi] ; esi - z_buffer |
810 | jge @f ; edi - Screen buffer |
||
811 | if Ext >= SSE2 |
||
812 | movdqa xmm0,xmm7 |
||
813 | psrld xmm0,ROUND |
||
814 | packssdw xmm0,xmm0 |
||
815 | packuswb xmm0,xmm0 |
||
816 | movd eax,xmm0 |
||
817 | stosw |
||
818 | shr eax,16 |
||
819 | stosb |
||
820 | end if |
||
821 | if (Ext=MMX) | (Ext=SSE) |
||
822 | movq mm0,mm3 ; mm0, mm1 - temp registers |
||
823 | psrld mm0,ROUND |
||
824 | movq mm1,mm4 |
||
825 | psrld mm1,ROUND |
||
826 | packssdw mm1,mm0 |
||
827 | packuswb mm1,mm6 |
||
9237 | leency | 828 | ; movd [edi],mm1 |
9740 | macgub | 829 | movd eax,mm1 |
830 | stosw |
||
831 | shr eax,16 |
||
832 | stosb |
||
9237 | leency | 833 | end if |
9740 | macgub | 834 | if Ext=NON |
835 | mov eax,.cr |
||
836 | sar eax,ROUND |
||
837 | stosb |
||
838 | mov eax,.cg |
||
839 | sar eax,ROUND |
||
840 | stosb |
||
841 | mov eax,.cb |
||
842 | sar eax,ROUND |
||
843 | stosb |
||
844 | end if |
||
845 | mov dword[esi],ebx |
||
9237 | leency | 846 | ;if Ext = NON |
9740 | macgub | 847 | jmp .no_skip |
9237 | leency | 848 | ;end if |
849 | @@: |
||
9740 | macgub | 850 | add edi,3 |
9237 | leency | 851 | .no_skip: |
9740 | macgub | 852 | add esi,4 |
9237 | leency | 853 | ;if Ext=NON |
9740 | macgub | 854 | add ebx,edx |
9237 | leency | 855 | ;end if |
9740 | macgub | 856 | if Ext >=SSE2 |
857 | paddd xmm7,xmm1 |
||
9237 | leency | 858 | end if |
9740 | macgub | 859 | if (Ext=MMX) | (Ext=SSE) |
860 | paddd mm3,mm2 |
||
861 | paddd mm4,mm5 |
||
862 | end if |
||
863 | if Ext = NON |
||
864 | mov eax,.dc_g |
||
865 | add .cg,eax |
||
866 | mov eax,.dc_b |
||
867 | add .cb,eax |
||
868 | mov eax,.dc_r |
||
869 | add .cr,eax |
||
870 | end if |
||
871 | loop .ddraw |
||
9237 | leency | 872 | |
873 | .gl_quit: |
||
9740 | macgub | 874 | mov esp,ebp |
9237 | leency | 875 | ret 26 |