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