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