Rev 8063 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5153 | IgorA | 1 | ; fill triangle profile |
2 | ; #define PROFILE |
||
3 | |||
4 | CLIP_XMIN equ (1<<0) |
||
5 | CLIP_XMAX equ (1<<1) |
||
6 | CLIP_YMIN equ (1<<2) |
||
7 | CLIP_YMAX equ (1<<3) |
||
8 | CLIP_ZMIN equ (1<<4) |
||
9 | CLIP_ZMAX equ (1<<5) |
||
10 | |||
6134 | IgorA | 11 | align 16 |
5153 | IgorA | 12 | proc gl_transform_to_viewport uses eax ebx ecx, context:dword,v:dword |
13 | mov eax,[context] |
||
14 | mov ebx,[v] |
||
15 | |||
16 | ; coordinates |
||
17 | fld1 |
||
8063 | IgorA | 18 | fdiv dword[ebx+GLVertex.pc+offs_W] ;st0 = 1/v.pc.W |
5153 | IgorA | 19 | |
8063 | IgorA | 20 | fld dword[ebx+GLVertex.pc+offs_X] ;st0 = v.pc.X |
5153 | IgorA | 21 | fmul st0,st1 |
8069 | IgorA | 22 | fmul dword[eax+GLContext.viewport+GLViewport.scale+offs_X] |
23 | fadd dword[eax+GLContext.viewport+GLViewport.trans+offs_X] |
||
8063 | IgorA | 24 | fistp dword[ebx+GLVertex.zp] ;v.zp.x = st0, st0 = st1 |
5153 | IgorA | 25 | |
8063 | IgorA | 26 | fld dword[ebx+GLVertex.pc+offs_Y] ;st0 = v.pc.Y |
5153 | IgorA | 27 | fmul st0,st1 |
8069 | IgorA | 28 | fmul dword[eax+GLContext.viewport+GLViewport.scale+offs_Y] |
29 | fadd dword[eax+GLContext.viewport+GLViewport.trans+offs_Y] |
||
30 | fistp dword[ebx+GLVertex.zp+ZBufferPoint.y] ;v.zp.y = st0, st0 = st1 |
||
5153 | IgorA | 31 | |
8063 | IgorA | 32 | fld dword[ebx+GLVertex.pc+offs_Z] ;st0 = v.pc.Z |
6145 | IgorA | 33 | fmulp |
8069 | IgorA | 34 | fmul dword[eax+GLContext.viewport+GLViewport.scale+offs_Z] |
35 | fadd dword[eax+GLContext.viewport+GLViewport.trans+offs_Z] |
||
36 | fistp dword[ebx+GLVertex.zp+ZBufferPoint.z] ;v.zp.z = st0, st0 = st1 |
||
5153 | IgorA | 37 | |
38 | ; color |
||
6523 | IgorA | 39 | cmp dword[eax+GLContext.lighting_enabled],0 ;if (context.lighting_enabled) |
5208 | IgorA | 40 | je @f |
8069 | IgorA | 41 | lea ecx,[ebx+GLVertex.zp+ZBufferPoint.b] |
5153 | IgorA | 42 | push ecx |
8069 | IgorA | 43 | add ecx,ZBufferPoint.g-ZBufferPoint.b |
5153 | IgorA | 44 | push ecx |
8069 | IgorA | 45 | add ecx,ZBufferPoint.r-ZBufferPoint.g |
5153 | IgorA | 46 | push ecx |
8063 | IgorA | 47 | stdcall RGBFtoRGBI, dword[ebx+GLVertex.color],dword[ebx+GLVertex.color+4],dword[ebx+GLVertex.color+8] |
5153 | IgorA | 48 | jmp .end_if |
6134 | IgorA | 49 | align 4 |
5153 | IgorA | 50 | @@: |
51 | ; no need to convert to integer if no lighting : take current color |
||
6523 | IgorA | 52 | mov ecx,[eax+GLContext.longcurrent_color] |
8069 | IgorA | 53 | mov dword[ebx+GLVertex.zp+ZBufferPoint.r],ecx |
6523 | IgorA | 54 | mov ecx,[eax+GLContext.longcurrent_color+4] |
8069 | IgorA | 55 | mov dword[ebx+GLVertex.zp+ZBufferPoint.g],ecx |
6523 | IgorA | 56 | mov ecx,[eax+GLContext.longcurrent_color+8] |
8069 | IgorA | 57 | mov dword[ebx+GLVertex.zp+ZBufferPoint.b],ecx |
5153 | IgorA | 58 | .end_if: |
59 | |||
60 | ; texture |
||
6523 | IgorA | 61 | cmp dword[eax+GLContext.texture_2d_enabled],0 |
5353 | IgorA | 62 | je @f |
6523 | IgorA | 63 | mov eax,[eax+GLContext.current_texture] ;eax = &context.current_texture |
6243 | IgorA | 64 | mov eax,[eax] ;eax = context.current_texture |
65 | ;[eax+offs_text_images] = im = &context.current_texture.images[0] |
||
66 | |||
67 | fild dword[eax+offs_text_images+offs_imag_s_bound] |
||
8063 | IgorA | 68 | fmul dword[ebx+GLVertex.tex_coord+offs_X] |
8069 | IgorA | 69 | fistp dword[ebx+GLVertex.zp+ZBufferPoint.s] |
6243 | IgorA | 70 | ;v.zp.s=(int)(v.tex_coord.X * im.s_bound) |
5153 | IgorA | 71 | |
6243 | IgorA | 72 | fild dword[eax+offs_text_images+offs_imag_t_bound] |
8063 | IgorA | 73 | fmul dword[ebx+GLVertex.tex_coord+offs_Y] |
8069 | IgorA | 74 | fistp dword[ebx+GLVertex.zp+ZBufferPoint.t] |
6243 | IgorA | 75 | ;v.zp.t=(int)(v.tex_coord.Y * im.t_bound) |
5153 | IgorA | 76 | @@: |
77 | ret |
||
78 | endp |
||
79 | |||
6134 | IgorA | 80 | align 16 |
5153 | IgorA | 81 | proc gl_add_select1 uses eax ebx ecx, context:dword, z1:dword,z2:dword,z3:dword |
82 | mov eax,[z1] |
||
83 | mov ebx,eax |
||
84 | cmp [z2],eax |
||
85 | jge @f |
||
86 | mov eax,[z2] |
||
87 | @@: |
||
88 | cmp [z3],eax |
||
89 | jge @f |
||
90 | mov eax,[z3] |
||
91 | @@: |
||
92 | cmp [z2],ebx |
||
93 | jle @f |
||
94 | mov ebx,[z2] |
||
95 | @@: |
||
96 | cmp [z3],ebx |
||
97 | jle @f |
||
98 | mov ebx,[z3] |
||
99 | @@: |
||
100 | mov ecx,0xffffffff |
||
101 | sub ecx,ebx |
||
102 | push ecx |
||
103 | mov ecx,0xffffffff |
||
104 | sub ecx,eax |
||
105 | push ecx |
||
106 | stdcall gl_add_select, [context] ;,0xffffffff-eax,0xffffffff-ebx |
||
107 | ret |
||
108 | endp |
||
109 | |||
110 | ; point |
||
111 | |||
6134 | IgorA | 112 | align 16 |
5153 | IgorA | 113 | proc gl_draw_point uses eax ebx, context:dword, p0:dword |
114 | mov ebx,[p0] |
||
8063 | IgorA | 115 | cmp dword[ebx+GLVertex.clip_code],0 ;if (p0.clip_code == 0) |
5153 | IgorA | 116 | jne @f |
117 | mov eax,[context] |
||
6523 | IgorA | 118 | cmp dword[eax+GLContext.render_mode],GL_SELECT |
5153 | IgorA | 119 | jne .els |
8069 | IgorA | 120 | stdcall gl_add_select, eax,dword[ebx+GLVertex.zp+ZBufferPoint.z],dword[ebx+GLVertex.zp+ZBufferPoint.z] ;p0.zp.z,p0.zp.z |
5153 | IgorA | 121 | jmp @f |
6134 | IgorA | 122 | align 4 |
5153 | IgorA | 123 | .els: |
8063 | IgorA | 124 | add ebx,GLVertex.zp |
6523 | IgorA | 125 | stdcall ZB_plot, dword[eax+GLContext.zb],ebx |
5153 | IgorA | 126 | @@: |
127 | ret |
||
128 | endp |
||
129 | |||
130 | ; line |
||
131 | |||
6172 | IgorA | 132 | ;input: |
133 | ;q - регистр с адресом вершины для интерполяции |
||
134 | ;p0 - регистр с адресом 1-й вершины |
||
135 | ;p1 - регистр с адресом 2-й вершины |
||
136 | ;t - float |
||
137 | macro interpolate q, p0, p1, t |
||
138 | { |
||
5153 | IgorA | 139 | fld dword[t] |
140 | |||
141 | ; интерполяция по координатам |
||
8063 | IgorA | 142 | fld dword[p1+GLVertex.pc] |
143 | fsub dword[p0+GLVertex.pc] |
||
5153 | IgorA | 144 | fmul st0,st1 |
8063 | IgorA | 145 | fadd dword[p0+GLVertex.pc] |
146 | fstp dword[q+GLVertex.pc] ;q.pc.X = p0.pc.X + (p1.pc.X - p0.pc.X) * t |
||
5153 | IgorA | 147 | |
8063 | IgorA | 148 | fld dword[p1+GLVertex.pc+offs_Y] |
149 | fsub dword[p0+GLVertex.pc+offs_Y] |
||
5153 | IgorA | 150 | fmul st0,st1 |
8063 | IgorA | 151 | fadd dword[p0+GLVertex.pc+offs_Y] |
152 | fstp dword[q+GLVertex.pc+offs_Y] |
||
5153 | IgorA | 153 | |
8063 | IgorA | 154 | fld dword[p1+GLVertex.pc+offs_Z] |
155 | fsub dword[p0+GLVertex.pc+offs_Z] |
||
5153 | IgorA | 156 | fmul st0,st1 |
8063 | IgorA | 157 | fadd dword[p0+GLVertex.pc+offs_Z] |
158 | fstp dword[q+GLVertex.pc+offs_Z] |
||
5153 | IgorA | 159 | |
8063 | IgorA | 160 | fld dword[p1+GLVertex.pc+offs_W] |
161 | fsub dword[p0+GLVertex.pc+offs_W] |
||
5153 | IgorA | 162 | fmul st0,st1 |
8063 | IgorA | 163 | fadd dword[p0+GLVertex.pc+offs_W] |
164 | fstp dword[q+GLVertex.pc+offs_W] |
||
5153 | IgorA | 165 | |
166 | ; интерполяция по цвету |
||
8063 | IgorA | 167 | fld dword[p1+GLVertex.color] |
168 | fsub dword[p0+GLVertex.color] |
||
5153 | IgorA | 169 | fmul st0,st1 |
8063 | IgorA | 170 | fadd dword[p0+GLVertex.color] |
171 | fstp dword[q+GLVertex.color] |
||
5153 | IgorA | 172 | |
8063 | IgorA | 173 | fld dword[p1+GLVertex.color+4] |
174 | fsub dword[p0+GLVertex.color+4] |
||
5153 | IgorA | 175 | fmul st0,st1 |
8063 | IgorA | 176 | fadd dword[p0+GLVertex.color+4] |
177 | fstp dword[q+GLVertex.color+4] |
||
5153 | IgorA | 178 | |
8063 | IgorA | 179 | fld dword[p1+GLVertex.color+8] |
180 | fsub dword[p0+GLVertex.color+8] |
||
6145 | IgorA | 181 | fmulp |
8063 | IgorA | 182 | fadd dword[p0+GLVertex.color+8] |
183 | fstp dword[q+GLVertex.color+8] |
||
6172 | IgorA | 184 | } |
5153 | IgorA | 185 | |
186 | ; |
||
187 | ; Line Clipping |
||
188 | ; |
||
189 | |||
190 | ; Line Clipping algorithm from 'Computer Graphics', Principles and |
||
191 | ; Practice |
||
192 | ; tmin,tmax -> &float |
||
6134 | IgorA | 193 | align 16 |
5153 | IgorA | 194 | proc ClipLine1 uses ebx, denom:dword,num:dword,tmin:dword,tmax:dword |
5278 | IgorA | 195 | fld dword[denom] |
196 | ftst |
||
5153 | IgorA | 197 | fstsw ax |
198 | sahf |
||
5278 | IgorA | 199 | jbe .els_0 ;if (denom>0) |
5153 | IgorA | 200 | fld dword[num] |
5278 | IgorA | 201 | fxch st1 |
202 | fdivp ;t=num/denom |
||
5153 | IgorA | 203 | mov ebx,[tmax] |
204 | fcom dword[ebx] |
||
205 | fstsw ax |
||
206 | sahf |
||
5278 | IgorA | 207 | ja .r0_f1 ;if (t>*tmax) return 0 |
5153 | IgorA | 208 | mov ebx,[tmin] |
209 | fcom dword[ebx] |
||
210 | fstsw ax |
||
211 | sahf |
||
5278 | IgorA | 212 | jbe .r1_f1 ;if (t>*tmin) *tmin=t |
213 | fstp dword[ebx] |
||
5153 | IgorA | 214 | jmp .r1 |
6134 | IgorA | 215 | align 4 |
5278 | IgorA | 216 | .els_0: ;else if (denom<0) |
217 | jae .els_1 |
||
5153 | IgorA | 218 | fld dword[num] |
5278 | IgorA | 219 | fxch st1 |
220 | fdivp ;t=num/denom |
||
5153 | IgorA | 221 | mov ebx,[tmin] |
222 | fcom dword[ebx] |
||
223 | fstsw ax |
||
224 | sahf |
||
5278 | IgorA | 225 | jb .r0_f1 ;if (t<*tmin) return 0 |
5153 | IgorA | 226 | mov ebx,[tmax] |
227 | fcom dword[ebx] |
||
228 | fstsw ax |
||
229 | sahf |
||
5278 | IgorA | 230 | jae .r1_f1 |
5153 | IgorA | 231 | fstp dword[ebx] ;if (t<*tmin) *tmax=t |
5278 | IgorA | 232 | jmp .r1 |
6134 | IgorA | 233 | align 4 |
5278 | IgorA | 234 | .els_1: ;else if (num>0) |
235 | ffree st0 ;denom |
||
236 | fincstp |
||
237 | fld dword[num] |
||
238 | ftst |
||
239 | fstsw ax |
||
240 | sahf |
||
241 | ja .r0_f1 ;if (num>0) return 0 |
||
242 | jmp .r1_f1 |
||
6134 | IgorA | 243 | align 4 |
5278 | IgorA | 244 | .r0_f1: ;return 0 & free st0 |
5218 | IgorA | 245 | ffree st0 |
246 | fincstp |
||
5278 | IgorA | 247 | .r0: ;return 0 |
5153 | IgorA | 248 | xor eax,eax |
249 | jmp .end_f |
||
6134 | IgorA | 250 | align 4 |
5278 | IgorA | 251 | .r1_f1: ;return 1 & free st0 |
5218 | IgorA | 252 | ffree st0 |
253 | fincstp |
||
5278 | IgorA | 254 | .r1: ;return 1 |
5153 | IgorA | 255 | xor eax,eax |
256 | inc eax |
||
257 | .end_f: |
||
258 | ret |
||
259 | endp |
||
260 | |||
6134 | IgorA | 261 | align 16 |
5218 | IgorA | 262 | proc gl_draw_line, context:dword, p1:dword, p2:dword |
5153 | IgorA | 263 | locals |
264 | d_x dd ? |
||
265 | d_y dd ? |
||
266 | d_z dd ? |
||
267 | d_w dd ? |
||
268 | x1 dd ? |
||
269 | y1 dd ? |
||
270 | z1 dd ? |
||
271 | w1 dd ? |
||
272 | q1 GLVertex ? |
||
273 | q2 GLVertex ? |
||
274 | tmin dd ? ;ebp-8 |
||
275 | tmax dd ? ;ebp-4 |
||
276 | endl |
||
5218 | IgorA | 277 | pushad |
5153 | IgorA | 278 | mov edx,[context] |
279 | mov edi,[p1] |
||
280 | mov esi,[p2] |
||
281 | |||
8063 | IgorA | 282 | cmp dword[edi+GLVertex.clip_code],0 |
5153 | IgorA | 283 | jne .els_i |
8063 | IgorA | 284 | cmp dword[esi+GLVertex.clip_code],0 |
5153 | IgorA | 285 | jne .els_i |
286 | ;if ( (p1.clip_code | p2.clip_code) == 0) |
||
6523 | IgorA | 287 | cmp dword[edx+GLContext.render_mode],GL_SELECT ;if (context.render_mode == GL_SELECT) |
5153 | IgorA | 288 | jne .els_1 |
8069 | IgorA | 289 | stdcall gl_add_select1, edx,dword[edi+GLVertex.zp+ZBufferPoint.z],\ |
290 | dword[esi+GLVertex.zp+ZBufferPoint.z],dword[esi+GLVertex.zp+ZBufferPoint.z] |
||
5153 | IgorA | 291 | jmp .end_f |
6134 | IgorA | 292 | align 4 |
5153 | IgorA | 293 | .els_1: |
8063 | IgorA | 294 | add edi,GLVertex.zp |
295 | add esi,GLVertex.zp |
||
5153 | IgorA | 296 | push esi |
297 | push edi |
||
6523 | IgorA | 298 | push dword[edx+GLContext.zb] |
299 | cmp dword[edx+GLContext.depth_test],0 |
||
5153 | IgorA | 300 | je .els_2 |
301 | ;if (context.depth_test) |
||
6523 | IgorA | 302 | call ZB_line_z ;, dword[edx+GLContext.zb],edi,esi |
5153 | IgorA | 303 | jmp .end_f |
6134 | IgorA | 304 | align 4 |
5153 | IgorA | 305 | .els_2: |
6523 | IgorA | 306 | call ZB_line ;, dword[edx+GLContext.zb],edi,esi |
5153 | IgorA | 307 | jmp .end_f |
6134 | IgorA | 308 | align 4 |
5153 | IgorA | 309 | .els_i: |
310 | ;else if ( (p1.clip_code & p2.clip_code) != 0 ) |
||
8063 | IgorA | 311 | mov eax,[edi+GLVertex.clip_code] |
312 | and eax,[esi+GLVertex.clip_code] |
||
6134 | IgorA | 313 | or eax,eax |
314 | jnz .end_f |
||
5153 | IgorA | 315 | .els_0: |
316 | |||
8063 | IgorA | 317 | fld dword[esi+GLVertex.pc+offs_X] |
318 | fsub dword[edi+GLVertex.pc+offs_X] |
||
5153 | IgorA | 319 | fstp dword[d_x] ;d_x = p2.pc.X - p1.pc.X |
8063 | IgorA | 320 | fld dword[esi+GLVertex.pc+offs_Y] |
321 | fsub dword[edi+GLVertex.pc+offs_Y] |
||
5153 | IgorA | 322 | fstp dword[d_y] ;d_y = p2.pc.Y - p1.pc.Y |
8063 | IgorA | 323 | fld dword[esi+GLVertex.pc+offs_Z] |
324 | fsub dword[edi+GLVertex.pc+offs_Z] |
||
5153 | IgorA | 325 | fstp dword[d_z] ;d_z = p2.pc.Z - p1.pc.Z |
8063 | IgorA | 326 | fld dword[esi+GLVertex.pc+offs_W] |
327 | fsub dword[edi+GLVertex.pc+offs_W] |
||
5153 | IgorA | 328 | fstp dword[d_w] ;d_w = p2.pc.W - p1.pc.W |
329 | |||
8063 | IgorA | 330 | mov eax,[edi+GLVertex.pc+offs_X] |
5153 | IgorA | 331 | mov [x1],eax ;x1 = p1.pc.X |
8063 | IgorA | 332 | mov eax,[edi+GLVertex.pc+offs_Y] |
5153 | IgorA | 333 | mov [y1],eax ;y1 = p1.pc.Y |
8063 | IgorA | 334 | mov eax,[edi+GLVertex.pc+offs_Z] |
5153 | IgorA | 335 | mov [z1],eax ;z1 = p1.pc.Z |
8063 | IgorA | 336 | mov eax,[edi+GLVertex.pc+offs_W] |
5153 | IgorA | 337 | mov [w1],eax ;w1 = p1.pc.W |
338 | |||
339 | mov dword[tmin],0.0 |
||
340 | mov dword[tmax],1.0 |
||
341 | |||
8063 | IgorA | 342 | lea eax,[ebp-4] |
5153 | IgorA | 343 | push eax ;толкаем в стек адрес &tmax |
344 | sub eax,4 |
||
345 | push eax ;толкаем в стек адрес &tmin |
||
346 | fld dword[x1] |
||
347 | fadd dword[w1] |
||
348 | fchs |
||
349 | fstp dword[esp-4] |
||
350 | fld dword[d_x] |
||
351 | fadd dword[d_w] |
||
352 | fstp dword[esp-8] |
||
353 | sub esp,8 |
||
354 | call ClipLine1 ;d_x+d_w,-x1-w1,&tmin,&tmax |
||
355 | bt eax,0 |
||
356 | jnc .end_f |
||
357 | |||
358 | sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax |
||
359 | fld dword[x1] |
||
360 | fsub dword[w1] |
||
361 | fstp dword[esp-4] |
||
362 | fld dword[d_w] |
||
363 | fsub dword[d_x] |
||
364 | fstp dword[esp-8] |
||
365 | sub esp,8 |
||
366 | call ClipLine1 ;-d_x+d_w,x1-w1,&tmin,&tmax |
||
367 | bt eax,0 |
||
368 | jnc .end_f |
||
369 | |||
370 | sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax |
||
371 | fld dword[y1] |
||
372 | fadd dword[w1] |
||
373 | fchs |
||
374 | fstp dword[esp-4] |
||
375 | fld dword[d_y] |
||
376 | fadd dword[d_w] |
||
377 | fstp dword[esp-8] |
||
378 | sub esp,8 |
||
379 | call ClipLine1 ;d_y+d_w,-y1-w1,&tmin,&tmax |
||
380 | bt eax,0 |
||
381 | jnc .end_f |
||
382 | |||
383 | sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax |
||
384 | fld dword[y1] |
||
385 | fsub dword[w1] |
||
386 | fstp dword[esp-4] |
||
387 | fld dword[d_w] |
||
388 | fsub dword[d_y] |
||
389 | fstp dword[esp-8] |
||
390 | sub esp,8 |
||
391 | call ClipLine1 ;-d_y+d_w,y1-w1,&tmin,&tmax |
||
392 | bt eax,0 |
||
393 | jnc .end_f |
||
394 | |||
395 | sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax |
||
396 | fld dword[z1] |
||
397 | fadd dword[w1] |
||
398 | fchs |
||
399 | fstp dword[esp-4] |
||
400 | fld dword[d_z] |
||
401 | fadd dword[d_w] |
||
402 | fstp dword[esp-8] |
||
403 | sub esp,8 |
||
404 | call ClipLine1 ;d_z+d_w,-z1-w1,&tmin,&tmax |
||
405 | bt eax,0 |
||
406 | jnc .end_f |
||
407 | |||
408 | sub esp,8 ;толкаем в стек адреса переменных &tmin и &tmax |
||
409 | fld dword[z1] |
||
410 | fsub dword[w1] |
||
411 | fstp dword[esp-4] |
||
412 | fld dword[d_w] |
||
413 | fsub dword[d_z] |
||
414 | fstp dword[esp-8] |
||
415 | sub esp,8 |
||
416 | call ClipLine1 ;-d_z+d_w,z1-w1,&tmin,&tmax |
||
417 | bt eax,0 |
||
418 | jnc .end_f |
||
419 | |||
8063 | IgorA | 420 | lea eax,[ebp-8-2*sizeof.GLVertex] ;eax = &q1 |
6172 | IgorA | 421 | interpolate eax,edi,esi,tmin |
5153 | IgorA | 422 | stdcall gl_transform_to_viewport, edx,eax |
423 | add eax,sizeof.GLVertex ;eax = &q2 |
||
6172 | IgorA | 424 | interpolate eax,edi,esi,tmax |
5153 | IgorA | 425 | stdcall gl_transform_to_viewport, edx,eax |
426 | |||
427 | sub eax,sizeof.GLVertex ;eax = &q1 |
||
8069 | IgorA | 428 | lea ebx,[eax+GLVertex.zp+ZBufferPoint.b] |
5153 | IgorA | 429 | push ebx |
8069 | IgorA | 430 | add ebx,ZBufferPoint.g-ZBufferPoint.b |
5153 | IgorA | 431 | push ebx |
8069 | IgorA | 432 | add ebx,ZBufferPoint.r-ZBufferPoint.g |
5153 | IgorA | 433 | push ebx |
8063 | IgorA | 434 | stdcall RGBFtoRGBI, dword[eax+GLVertex.color],dword[eax+GLVertex.color+4],dword[eax+GLVertex.color+8] |
5153 | IgorA | 435 | |
436 | add eax,sizeof.GLVertex ;eax = &q2 |
||
8069 | IgorA | 437 | lea ebx,[eax+GLVertex.zp+ZBufferPoint.b] |
5153 | IgorA | 438 | push ebx |
8069 | IgorA | 439 | add ebx,ZBufferPoint.g-ZBufferPoint.b |
5153 | IgorA | 440 | push ebx |
8069 | IgorA | 441 | add ebx,ZBufferPoint.r-ZBufferPoint.g |
5153 | IgorA | 442 | push ebx |
8063 | IgorA | 443 | stdcall RGBFtoRGBI, dword[eax+GLVertex.color],dword[eax+GLVertex.color+4],dword[eax+GLVertex.color+8] |
5153 | IgorA | 444 | |
8063 | IgorA | 445 | add eax,GLVertex.zp ;eax = &q2.zp |
5153 | IgorA | 446 | push eax |
447 | sub eax,sizeof.GLVertex ;eax = &q1.zp |
||
448 | push eax |
||
6523 | IgorA | 449 | push dword[edx+GLContext.zb] |
450 | cmp dword[edx+GLContext.depth_test],0 |
||
5153 | IgorA | 451 | je .els_3 |
452 | call ZB_line_z ;(context.zb,&q1.zp,&q2.zp) |
||
453 | jmp .end_f |
||
6134 | IgorA | 454 | align 4 |
5153 | IgorA | 455 | .els_3: |
456 | call ZB_line ;(context.zb,&q1.zp,&q2.zp) |
||
457 | .end_f: |
||
5218 | IgorA | 458 | popad |
5153 | IgorA | 459 | ret |
460 | endp |
||
461 | |||
462 | ; triangle |
||
463 | |||
464 | ; |
||
465 | ; Clipping |
||
466 | ; |
||
467 | |||
468 | ; We clip the segment [a,b] against the 6 planes of the normal volume. |
||
469 | ; We compute the point 'c' of intersection and the value of the parameter 't' |
||
470 | ; of the intersection if x=a+t(b-a). |
||
471 | ; |
||
472 | ; sign: 0 -> '-', 1 -> '+' |
||
473 | macro clip_func sign,dir,dir1,dir2 |
||
474 | { |
||
475 | locals |
||
476 | t dd ? |
||
477 | d_X dd ? |
||
478 | d_Y dd ? |
||
479 | d_Z dd ? |
||
480 | d_W dd ? |
||
481 | endl |
||
482 | mov edx,[a] |
||
483 | mov ebx,[b] |
||
484 | mov ecx,[c] |
||
5175 | IgorA | 485 | fld dword[ebx+offs_X] |
486 | fsub dword[edx+offs_X] |
||
5153 | IgorA | 487 | fstp dword[d_X] ;d_X = (b.X - a.X) |
5175 | IgorA | 488 | fld dword[ebx+offs_Y] |
489 | fsub dword[edx+offs_Y] |
||
5153 | IgorA | 490 | fstp dword[d_Y] ;d_Y = (b.Y - a.Y) |
5175 | IgorA | 491 | fld dword[ebx+offs_Z] |
492 | fsub dword[edx+offs_Z] |
||
5153 | IgorA | 493 | fstp dword[d_Z] ;d_Z = (b.Z - a.Z) |
5175 | IgorA | 494 | fld dword[ebx+offs_W] |
495 | fsub dword[edx+offs_W] |
||
5153 | IgorA | 496 | fst dword[d_W] ;d_W = (b.W - a.W) |
497 | if sign eq 0 |
||
498 | fadd dword[d#dir] |
||
499 | else |
||
500 | fsub dword[d#dir] |
||
501 | end if |
||
502 | |||
5218 | IgorA | 503 | ftst |
5153 | IgorA | 504 | fstsw ax |
505 | sahf |
||
5208 | IgorA | 506 | jne @f |
507 | fldz |
||
5153 | IgorA | 508 | fst dword[t] ;t=0 |
509 | jmp .e_zero |
||
6134 | IgorA | 510 | align 4 |
5153 | IgorA | 511 | @@: ;else |
512 | fld dword[edx+offs#dir] |
||
513 | if sign eq 0 |
||
514 | fchs |
||
515 | end if |
||
516 | fsub dword[edx+offs_W] |
||
517 | fdiv st0,st1 |
||
518 | fst dword[t] ;t = ( sign a.dir - a.W) / den |
||
519 | .e_zero: |
||
520 | |||
521 | fmul dword[d#dir1] ;st0 = t * d.dir1 |
||
522 | fadd dword[edx+offs#dir1] |
||
523 | fstp dword[ecx+offs#dir1] ;c.dir1 = a.dir1 + t * d.dir1 |
||
524 | |||
5208 | IgorA | 525 | ffree st0 |
526 | fincstp |
||
527 | |||
5153 | IgorA | 528 | fld dword[t] |
529 | fmul dword[d#dir2] ;st0 = t * d.dir2 |
||
530 | fadd dword[edx+offs#dir2] |
||
531 | fstp dword[ecx+offs#dir2] ;c.dir2 = a.dir2 + t * d.dir2 |
||
532 | |||
533 | fld dword[t] |
||
534 | fmul dword[d_W] |
||
535 | fadd dword[edx+offs_W] |
||
536 | fst dword[ecx+offs_W] ;c.W = a.W + t * d_W |
||
537 | |||
538 | if sign eq 0 |
||
539 | fchs |
||
540 | end if |
||
541 | fstp dword[ecx+offs#dir] ;c.dir = sign c.W |
||
542 | mov eax,[t] |
||
543 | } |
||
544 | |||
6134 | IgorA | 545 | align 16 |
5153 | IgorA | 546 | proc clip_xmin uses ebx ecx edx, c:dword, a:dword, b:dword |
547 | clip_func 0,_X,_Y,_Z |
||
548 | ret |
||
549 | endp |
||
550 | |||
6134 | IgorA | 551 | align 16 |
5153 | IgorA | 552 | proc clip_xmax uses ebx ecx edx, c:dword, a:dword, b:dword |
553 | clip_func 1,_X,_Y,_Z |
||
554 | ret |
||
555 | endp |
||
556 | |||
6134 | IgorA | 557 | align 16 |
5153 | IgorA | 558 | proc clip_ymin uses ebx ecx edx, c:dword, a:dword, b:dword |
559 | clip_func 0,_Y,_X,_Z |
||
560 | ret |
||
561 | endp |
||
562 | |||
6134 | IgorA | 563 | align 16 |
5153 | IgorA | 564 | proc clip_ymax uses ebx ecx edx, c:dword, a:dword, b:dword |
565 | clip_func 1,_Y,_X,_Z |
||
566 | ret |
||
567 | endp |
||
568 | |||
6134 | IgorA | 569 | align 16 |
5153 | IgorA | 570 | proc clip_zmin uses ebx ecx edx, c:dword, a:dword, b:dword |
571 | clip_func 0,_Z,_X,_Y |
||
572 | ret |
||
573 | endp |
||
574 | |||
6134 | IgorA | 575 | align 16 |
5153 | IgorA | 576 | proc clip_zmax uses ebx ecx edx, c:dword, a:dword, b:dword |
577 | clip_func 1,_Z,_X,_Y |
||
578 | ret |
||
579 | endp |
||
580 | |||
581 | align 4 |
||
582 | clip_proc dd clip_xmin,clip_xmax, clip_ymin,clip_ymax, clip_zmin,clip_zmax |
||
583 | |||
6172 | IgorA | 584 | ;input: |
585 | ;edi - q |
||
6134 | IgorA | 586 | align 16 |
6172 | IgorA | 587 | proc updateTmp uses eax ecx edx, context:dword, p0:dword, p1:dword, t:dword |
5208 | IgorA | 588 | mov edx,[context] |
589 | mov eax,[p0] |
||
6523 | IgorA | 590 | cmp dword[edx+GLContext.current_shade_model],GL_SMOOTH ;if (context.current_shade_model == GL_SMOOTH) |
5175 | IgorA | 591 | jne .els_0 |
5208 | IgorA | 592 | mov ecx,[p1] |
8063 | IgorA | 593 | fld dword[ecx+GLVertex.color] |
594 | fsub dword[eax+GLVertex.color] |
||
5208 | IgorA | 595 | fmul dword[t] |
8063 | IgorA | 596 | fadd dword[eax+GLVertex.color] |
597 | fstp dword[edi+GLVertex.color] ;q.color.v[0]=p0.color.v[0] + (p1.color.v[0]-p0.color.v[0])*t |
||
598 | fld dword[ecx+GLVertex.color+4] |
||
599 | fsub dword[eax+GLVertex.color+4] |
||
5208 | IgorA | 600 | fmul dword[t] |
8063 | IgorA | 601 | fadd dword[eax+GLVertex.color+4] |
602 | fstp dword[edi+GLVertex.color+4] ;q.color.v[1]=p0.color.v[1] + (p1.color.v[1]-p0.color.v[1])*t |
||
603 | fld dword[ecx+GLVertex.color+8] |
||
604 | fsub dword[eax+GLVertex.color+8] |
||
5208 | IgorA | 605 | fmul dword[t] |
8063 | IgorA | 606 | fadd dword[eax+GLVertex.color+8] |
607 | fstp dword[edi+GLVertex.color+8] ;q.color.v[2]=p0.color.v[2] + (p1.color.v[2]-p0.color.v[2])*t |
||
5175 | IgorA | 608 | jmp @f |
6134 | IgorA | 609 | align 4 |
5175 | IgorA | 610 | .els_0: |
8063 | IgorA | 611 | mov ecx,[eax+GLVertex.color] |
612 | mov [edi+GLVertex.color],ecx ;q.color.v[0]=p0.color.v[0] |
||
613 | mov ecx,[eax+GLVertex.color+4] |
||
614 | mov [edi+GLVertex.color+4],ecx ;q.color.v[1]=p0.color.v[1] |
||
615 | mov ecx,[eax+GLVertex.color+8] |
||
616 | mov [edi+GLVertex.color+8],ecx ;q.color.v[2]=p0.color.v[2] |
||
5175 | IgorA | 617 | @@: |
5153 | IgorA | 618 | |
6523 | IgorA | 619 | cmp dword[edx+GLContext.texture_2d_enabled],0 ;if (context.texture_2d_enabled) |
5175 | IgorA | 620 | je @f |
5208 | IgorA | 621 | mov ecx,[p1] |
8063 | IgorA | 622 | fld dword[ecx+GLVertex.tex_coord+offs_X] |
623 | fsub dword[eax+GLVertex.tex_coord+offs_X] |
||
5208 | IgorA | 624 | fmul dword[t] |
8063 | IgorA | 625 | fadd dword[eax+GLVertex.tex_coord+offs_X] |
626 | fstp dword[edi+GLVertex.tex_coord+offs_X] ;q.tex_coord.X=p0.tex_coord.X + (p1.tex_coord.X-p0.tex_coord.X)*t |
||
627 | fld dword[ecx+GLVertex.tex_coord+offs_Y] |
||
628 | fsub dword[eax+GLVertex.tex_coord+offs_Y] |
||
5208 | IgorA | 629 | fmul dword[t] |
8063 | IgorA | 630 | fadd dword[eax+GLVertex.tex_coord+offs_Y] |
631 | fstp dword[edi+GLVertex.tex_coord+offs_Y] ;q.tex_coord.Y=p0.tex_coord.Y + (p1.tex_coord.Y-p0.tex_coord.Y)*t |
||
5175 | IgorA | 632 | @@: |
5153 | IgorA | 633 | |
8063 | IgorA | 634 | stdcall gl_clipcode, [edi+GLVertex.pc+offs_X],[edi+GLVertex.pc+offs_Y],\ |
635 | [edi+GLVertex.pc+offs_Z],[edi+GLVertex.pc+offs_W] |
||
636 | mov dword[edi+GLVertex.clip_code],eax |
||
5353 | IgorA | 637 | or eax,eax ;if (q.clip_code==0) |
638 | jnz @f |
||
6172 | IgorA | 639 | stdcall gl_transform_to_viewport,[context],edi |
8069 | IgorA | 640 | lea eax,[edi+GLVertex.zp+ZBufferPoint.b] |
5208 | IgorA | 641 | push eax |
8069 | IgorA | 642 | add eax,ZBufferPoint.g-ZBufferPoint.b |
5208 | IgorA | 643 | push eax |
8069 | IgorA | 644 | add eax,ZBufferPoint.r-ZBufferPoint.g |
5208 | IgorA | 645 | push eax |
8063 | IgorA | 646 | stdcall RGBFtoRGBI, dword[edi+GLVertex.color],dword[edi+GLVertex.color+4],dword[edi+GLVertex.color+8] |
5208 | IgorA | 647 | @@: |
5175 | IgorA | 648 | ret |
649 | endp |
||
5153 | IgorA | 650 | |
6134 | IgorA | 651 | align 16 |
5175 | IgorA | 652 | proc gl_draw_triangle, context:dword, p0:dword, p1:dword, p2:dword |
653 | locals |
||
654 | cc rd 3 |
||
655 | front dd ? |
||
656 | norm dd ? ;float |
||
657 | endl |
||
658 | pushad |
||
659 | mov ebx,[p0] |
||
660 | mov ecx,[p1] |
||
661 | mov edx,[p2] |
||
8063 | IgorA | 662 | mov edi,[ebx+GLVertex.clip_code] |
5175 | IgorA | 663 | mov dword[cc],edi |
8063 | IgorA | 664 | mov eax,[ecx+GLVertex.clip_code] |
5175 | IgorA | 665 | mov dword[cc+4],eax |
666 | or edi,eax |
||
8063 | IgorA | 667 | mov eax,[edx+GLVertex.clip_code] |
5175 | IgorA | 668 | mov dword[cc+8],eax |
5208 | IgorA | 669 | or edi,eax ;co = cc[0] | cc[1] | cc[2] |
5153 | IgorA | 670 | |
5175 | IgorA | 671 | ; we handle the non clipped case here to go faster |
5353 | IgorA | 672 | ;or edi,___ - было выше |
673 | jnz .els_0 |
||
674 | ;if (co==0) |
||
8069 | IgorA | 675 | mov edi,dword[edx+GLVertex.zp+ZBufferPoint.x] |
676 | sub edi,dword[ebx+GLVertex.zp+ZBufferPoint.x] |
||
5418 | IgorA | 677 | mov dword[norm],edi ;p2.x-p0.x |
5175 | IgorA | 678 | fild dword[norm] |
8069 | IgorA | 679 | mov edi,dword[ecx+GLVertex.zp+ZBufferPoint.y] |
680 | sub edi,dword[ebx+GLVertex.zp+ZBufferPoint.y] |
||
5418 | IgorA | 681 | mov dword[norm],edi ;p1.y-p0.y |
5175 | IgorA | 682 | fimul dword[norm] |
5418 | IgorA | 683 | fchs |
8069 | IgorA | 684 | mov edi,dword[ecx+GLVertex.zp+ZBufferPoint.x] |
685 | sub edi,dword[ebx+GLVertex.zp+ZBufferPoint.x] |
||
5418 | IgorA | 686 | mov dword[norm],edi ;p1.x-p0.x |
5175 | IgorA | 687 | fild dword[norm] |
8069 | IgorA | 688 | mov edi,dword[edx+GLVertex.zp+ZBufferPoint.y] |
689 | sub edi,dword[ebx+GLVertex.zp+ZBufferPoint.y] |
||
5418 | IgorA | 690 | mov dword[norm],edi ;p2.y-p0.y |
5175 | IgorA | 691 | fimul dword[norm] |
5418 | IgorA | 692 | faddp |
5175 | IgorA | 693 | ;st0 = (p1.zp.x-p0.zp.x)*(p2.zp.y-p0.zp.y) - (p2.zp.x-p0.zp.x)*(p1.zp.y-p0.zp.y) |
5153 | IgorA | 694 | |
5175 | IgorA | 695 | mov dword[front],0 |
5418 | IgorA | 696 | ftst |
5175 | IgorA | 697 | fstsw ax |
5418 | IgorA | 698 | ffree st0 |
699 | fincstp |
||
5175 | IgorA | 700 | sahf |
701 | je .end_f |
||
5418 | IgorA | 702 | jae @f |
703 | inc dword[front] ;front = norm < 0.0 |
||
5175 | IgorA | 704 | @@: |
705 | mov edi,[context] |
||
6523 | IgorA | 706 | mov eax,dword[edi+GLContext.current_front_face] |
5175 | IgorA | 707 | xor dword[front],eax ;front ^= context.current_front_face |
5418 | IgorA | 708 | |
5175 | IgorA | 709 | ; back face culling |
6523 | IgorA | 710 | cmp dword[edi+GLContext.cull_face_enabled],0 |
5175 | IgorA | 711 | je .els_1 |
712 | ; most used case first |
||
6523 | IgorA | 713 | cmp dword[edi+GLContext.current_cull_face],GL_BACK |
5175 | IgorA | 714 | jne @f |
715 | cmp dword[front],0 |
||
716 | je .end_f |
||
6523 | IgorA | 717 | stdcall dword[edi+GLContext.draw_triangle_front], edi,ebx,ecx,edx |
5175 | IgorA | 718 | jmp .end_f |
6134 | IgorA | 719 | align 4 |
5175 | IgorA | 720 | @@: |
6523 | IgorA | 721 | cmp dword[edi+GLContext.current_cull_face],GL_FRONT |
5175 | IgorA | 722 | jne .end_f |
723 | cmp dword[front],0 |
||
724 | jne .end_f |
||
6523 | IgorA | 725 | stdcall dword[edi+GLContext.draw_triangle_back], edi,ebx,ecx,edx |
5175 | IgorA | 726 | jmp .end_f |
6134 | IgorA | 727 | align 4 |
5175 | IgorA | 728 | .els_1: |
729 | ; no culling |
||
730 | cmp dword[front],0 |
||
731 | je @f |
||
6523 | IgorA | 732 | stdcall dword[edi+GLContext.draw_triangle_front], edi,ebx,ecx,edx |
5213 | IgorA | 733 | jmp .end_f |
6134 | IgorA | 734 | align 4 |
5175 | IgorA | 735 | @@: |
6523 | IgorA | 736 | stdcall dword[edi+GLContext.draw_triangle_back], edi,ebx,ecx,edx |
5175 | IgorA | 737 | jmp .end_f |
6134 | IgorA | 738 | align 4 |
5175 | IgorA | 739 | .els_0: |
5208 | IgorA | 740 | ;eax = cc[2] |
5175 | IgorA | 741 | and eax,[cc] |
5208 | IgorA | 742 | and eax,[cc+4] ;eax = c_and = cc[0] & cc[1] & cc[2] |
5353 | IgorA | 743 | or eax,eax ;if (c_and==0) |
744 | jnz .end_f |
||
5175 | IgorA | 745 | stdcall gl_draw_triangle_clip, [context],ebx,ecx,edx,0 |
746 | .end_f: |
||
747 | popad |
||
748 | ret |
||
749 | endp |
||
5153 | IgorA | 750 | |
6134 | IgorA | 751 | align 16 |
5175 | IgorA | 752 | proc gl_draw_triangle_clip, context:dword, p0:dword, p1:dword, p2:dword, clip_bit:dword |
753 | locals |
||
754 | co dd ? |
||
755 | cc rd 3 |
||
756 | edge_flag_tmp dd ? |
||
757 | clip_mask dd ? |
||
5208 | IgorA | 758 | q rd 3 ;GLVertex* |
5175 | IgorA | 759 | tmp1 GLVertex ? |
760 | tmp2 GLVertex ? |
||
761 | endl |
||
762 | pushad |
||
763 | mov ebx,[p0] |
||
764 | mov ecx,[p1] |
||
765 | mov edx,[p2] |
||
5208 | IgorA | 766 | |
8063 | IgorA | 767 | mov edi,[ebx+GLVertex.clip_code] |
5208 | IgorA | 768 | mov [cc],edi |
8063 | IgorA | 769 | mov eax,[ecx+GLVertex.clip_code] |
5208 | IgorA | 770 | mov [cc+4],eax |
5175 | IgorA | 771 | or edi,eax |
8063 | IgorA | 772 | mov eax,[edx+GLVertex.clip_code] |
5208 | IgorA | 773 | mov [cc+8],eax |
5175 | IgorA | 774 | or edi,eax |
5208 | IgorA | 775 | mov [co],edi ;co = cc[0] | cc[1] | cc[2] |
5175 | IgorA | 776 | |
5353 | IgorA | 777 | or edi,edi ;if (co == 0) |
778 | jnz .els_0 |
||
5175 | IgorA | 779 | stdcall gl_draw_triangle, [context],ebx,ecx,edx |
780 | jmp .end_f |
||
6134 | IgorA | 781 | align 4 |
5175 | IgorA | 782 | .els_0: |
5208 | IgorA | 783 | ;eax = cc[2] |
5175 | IgorA | 784 | and eax,[cc] |
5208 | IgorA | 785 | and eax,[cc+4] ;c_and = cc[0] & cc[1] & cc[2] |
5175 | IgorA | 786 | |
787 | ; the triangle is completely outside |
||
5353 | IgorA | 788 | or eax,eax ;if (c_and!=0) return |
789 | jnz .end_f |
||
5175 | IgorA | 790 | |
5208 | IgorA | 791 | ; find the next direction to clip |
792 | .cycle_0: ;while (clip_bit < 6 && (co & (1 << clip_bit)) == 0) |
||
793 | cmp dword[clip_bit],6 |
||
794 | jge .cycle_0_end |
||
795 | xor eax,eax |
||
796 | inc eax |
||
797 | mov ecx,[clip_bit] |
||
798 | shl eax,cl |
||
799 | and eax,[co] |
||
5353 | IgorA | 800 | or eax,eax |
801 | jnz .cycle_0_end |
||
5208 | IgorA | 802 | inc dword[clip_bit] |
803 | jmp .cycle_0 |
||
6134 | IgorA | 804 | align 4 |
5208 | IgorA | 805 | .cycle_0_end: |
5153 | IgorA | 806 | |
5175 | IgorA | 807 | ; this test can be true only in case of rounding errors |
808 | cmp dword[clip_bit],6 |
||
809 | if 0 |
||
810 | jne @f |
||
5153 | IgorA | 811 | ; printf("Error:\n"); |
812 | ; printf("%f %f %f %f\n",p0->pc.X,p0->pc.Y,p0->pc.Z,p0->pc.W); |
||
813 | ; printf("%f %f %f %f\n",p1->pc.X,p1->pc.Y,p1->pc.Z,p1->pc.W); |
||
814 | ; printf("%f %f %f %f\n",p2->pc.X,p2->pc.Y,p2->pc.Z,p2->pc.W); |
||
5175 | IgorA | 815 | jmp .end_f |
816 | @@: |
||
5208 | IgorA | 817 | end if |
818 | if 1 |
||
5175 | IgorA | 819 | je .end_f |
820 | end if |
||
5153 | IgorA | 821 | |
5208 | IgorA | 822 | xor eax,eax |
823 | inc eax |
||
824 | mov ecx,[clip_bit] |
||
825 | shl eax,cl |
||
826 | mov [clip_mask],eax ;1 << clip_bit |
||
827 | mov edi,[cc] |
||
828 | xor edi,[cc+4] |
||
829 | xor edi,[cc+8] |
||
830 | and eax,edi ;eax = co1 = (cc[0] ^ cc[1] ^ cc[2]) & clip_mask |
||
5153 | IgorA | 831 | |
5208 | IgorA | 832 | mov ecx,[p1] ;востанавливаем после shl ___,cl |
5153 | IgorA | 833 | |
5353 | IgorA | 834 | or eax,eax ;if (co1) |
835 | jz .els_1 |
||
5208 | IgorA | 836 | ; one point outside |
837 | mov eax,[cc] |
||
838 | and eax,[clip_mask] |
||
5353 | IgorA | 839 | or eax,eax ;if (cc[0] & clip_mask) |
840 | jz .els_2 |
||
5208 | IgorA | 841 | ;q[0]=p0 q[1]=p1 q[2]=p2 |
842 | mov [q],ebx |
||
843 | mov [q+4],ecx |
||
844 | mov [q+8],edx |
||
845 | jmp .els_2_end |
||
6134 | IgorA | 846 | align 4 |
5208 | IgorA | 847 | .els_2: |
848 | mov eax,[cc+4] |
||
849 | and eax,[clip_mask] |
||
5353 | IgorA | 850 | or eax,eax ;else if (cc[1] & clip_mask) |
851 | jz .els_3 |
||
5208 | IgorA | 852 | ;q[0]=p1 q[1]=p2 q[2]=p0 |
853 | mov [q],ecx |
||
854 | mov [q+4],edx |
||
855 | mov [q+8],ebx |
||
856 | jmp .els_2_end |
||
6134 | IgorA | 857 | align 4 |
5208 | IgorA | 858 | .els_3: |
859 | ;q[0]=p2 q[1]=p0 q[2]=p1 |
||
860 | mov [q],edx |
||
861 | mov [q+4],ebx |
||
862 | mov [q+8],ecx |
||
863 | .els_2_end: |
||
5153 | IgorA | 864 | |
5208 | IgorA | 865 | mov ebx,[q] |
8063 | IgorA | 866 | add ebx,GLVertex.pc |
5208 | IgorA | 867 | mov ecx,[q+4] |
8063 | IgorA | 868 | add ecx,GLVertex.pc |
5208 | IgorA | 869 | mov edx,[q+8] |
8063 | IgorA | 870 | add edx,GLVertex.pc |
5153 | IgorA | 871 | |
5208 | IgorA | 872 | lea eax,[clip_proc] |
873 | mov edi,[clip_bit] |
||
8063 | IgorA | 874 | lea eax,[eax+4*edi] |
875 | lea edi,[ebp-(2*sizeof.GLVertex)+GLVertex.pc] |
||
5208 | IgorA | 876 | stdcall dword[eax],edi,ebx,ecx ;clip_proc[clip_bit](&tmp1.pc,&q[0].pc,&q[1].pc) |
8063 | IgorA | 877 | sub edi,GLVertex.pc |
5153 | IgorA | 878 | |
8063 | IgorA | 879 | sub ebx,GLVertex.pc |
880 | sub ecx,GLVertex.pc |
||
6172 | IgorA | 881 | stdcall updateTmp,[context],ebx,ecx,eax ;(c,&tmp1,q[0],q[1],tt) |
8063 | IgorA | 882 | add ebx,GLVertex.pc |
5153 | IgorA | 883 | |
5208 | IgorA | 884 | lea eax,[clip_proc] |
885 | mov edi,[clip_bit] |
||
8063 | IgorA | 886 | lea eax,[eax+4*edi] |
887 | lea edi,[ebp-sizeof.GLVertex+GLVertex.pc] |
||
5208 | IgorA | 888 | stdcall dword[eax],edi,ebx,edx ;clip_proc[clip_bit](&tmp2.pc,&q[0].pc,&q[2].pc) |
8063 | IgorA | 889 | sub edi,GLVertex.pc |
890 | sub ebx,GLVertex.pc |
||
891 | sub edx,GLVertex.pc |
||
6172 | IgorA | 892 | stdcall updateTmp,[context],ebx,edx,eax ;(c,&tmp2,q[0],q[2],tt) |
5208 | IgorA | 893 | |
8063 | IgorA | 894 | mov eax,[ebx+GLVertex.edge_flag] |
5353 | IgorA | 895 | mov [tmp1.edge_flag],eax ;q[0].edge_flag |
8063 | IgorA | 896 | mov eax,[edx+GLVertex.edge_flag] |
5208 | IgorA | 897 | mov [edge_flag_tmp],eax ;q[2].edge_flag |
8063 | IgorA | 898 | mov dword[edx+GLVertex.edge_flag],0 ;q[2].edge_flag=0 |
5208 | IgorA | 899 | mov eax,[clip_bit] |
900 | inc eax |
||
901 | push eax ;для вызова нижней функции |
||
8063 | IgorA | 902 | lea edi,[ebp-2*sizeof.GLVertex] |
5208 | IgorA | 903 | stdcall gl_draw_triangle_clip,[context],edi,ecx,edx,eax ;gl_draw_triangle_clip(c,&tmp1,q[1],q[2],clip_bit+1) |
904 | |||
905 | mov dword[tmp2.edge_flag],0 |
||
906 | mov dword[tmp1.edge_flag],0 |
||
907 | mov eax,[edge_flag_tmp] |
||
8063 | IgorA | 908 | mov [edx+GLVertex.edge_flag],eax ;q[2].edge_flag=edge_flag_tmp |
5208 | IgorA | 909 | push edx |
910 | push edi |
||
911 | add edi,sizeof.GLVertex ;edi = &tmp2 |
||
912 | stdcall gl_draw_triangle_clip,[context],edi ;gl_draw_triangle_clip(c,&tmp2,&tmp1,q[2],clip_bit+1) |
||
913 | jmp .end_f |
||
6134 | IgorA | 914 | align 4 |
5208 | IgorA | 915 | .els_1: |
916 | ; two points outside |
||
917 | mov eax,[cc] |
||
918 | and eax,[clip_mask] |
||
919 | cmp eax,0 ;if (cc[0] & clip_mask)==0 |
||
920 | jne .els_4 |
||
921 | ;q[0]=p0 q[1]=p1 q[2]=p2 |
||
922 | mov [q],ebx |
||
923 | mov [q+4],ecx |
||
924 | mov [q+8],edx |
||
925 | jmp .els_4_end |
||
6134 | IgorA | 926 | align 4 |
5208 | IgorA | 927 | .els_4: |
928 | mov eax,[cc+4] |
||
929 | and eax,[clip_mask] |
||
930 | cmp eax,0 ;else if (cc[1] & clip_mask)==0 |
||
931 | jne .els_5 |
||
932 | ;q[0]=p1 q[1]=p2 q[2]=p0 |
||
933 | mov [q],ecx |
||
934 | mov [q+4],edx |
||
935 | mov [q+8],ebx |
||
936 | jmp .els_4_end |
||
6134 | IgorA | 937 | align 4 |
5208 | IgorA | 938 | .els_5: |
939 | ;q[0]=p2 q[1]=p0 q[2]=p1 |
||
940 | mov [q],edx |
||
941 | mov [q+4],ebx |
||
942 | mov [q+8],ecx |
||
943 | .els_4_end: |
||
944 | |||
945 | mov ebx,[q] |
||
8063 | IgorA | 946 | add ebx,GLVertex.pc |
5208 | IgorA | 947 | mov ecx,[q+4] |
8063 | IgorA | 948 | add ecx,GLVertex.pc |
5208 | IgorA | 949 | mov edx,[q+8] |
8063 | IgorA | 950 | add edx,GLVertex.pc |
5208 | IgorA | 951 | |
952 | lea eax,[clip_proc] |
||
953 | mov edi,[clip_bit] |
||
8063 | IgorA | 954 | lea eax,[eax+4*edi] |
955 | lea edi,[ebp-(2*sizeof.GLVertex)+GLVertex.pc] |
||
5208 | IgorA | 956 | stdcall dword[eax],edi,ebx,ecx ;clip_proc[clip_bit](&tmp1.pc,&q[0].pc,&q[1].pc) |
8063 | IgorA | 957 | sub edi,GLVertex.pc |
6172 | IgorA | 958 | stdcall updateTmp,[context],[q],[q+4],eax |
5208 | IgorA | 959 | |
960 | lea eax,[clip_proc] |
||
961 | mov edi,[clip_bit] |
||
8063 | IgorA | 962 | lea eax,[eax+4*edi] |
963 | lea edi,[ebp-sizeof.GLVertex+GLVertex.pc] |
||
5208 | IgorA | 964 | stdcall dword[eax],edi,ebx,edx ;clip_proc[clip_bit](&tmp2.pc,&q[0].pc,&q[2].pc) |
8063 | IgorA | 965 | sub edi,GLVertex.pc |
6172 | IgorA | 966 | stdcall updateTmp,[context],[q],[q+8],eax |
5208 | IgorA | 967 | |
5353 | IgorA | 968 | mov dword[tmp1.edge_flag],1 |
8063 | IgorA | 969 | mov eax,[edx+GLVertex.edge_flag-GLVertex.pc] |
5353 | IgorA | 970 | mov dword[tmp2.edge_flag],eax ;tmp2.edge_flag = q[2].edge_flag |
5208 | IgorA | 971 | mov eax,[clip_bit] |
972 | inc eax |
||
973 | push eax |
||
974 | push edi |
||
975 | sub edi,sizeof.GLVertex |
||
976 | stdcall gl_draw_triangle_clip,[context],[q],edi ;gl_draw_triangle_clip(c,q[0],&tmp1,&tmp2,clip_bit+1) |
||
5175 | IgorA | 977 | .end_f: |
978 | popad |
||
979 | ret |
||
980 | endp |
||
5153 | IgorA | 981 | |
6134 | IgorA | 982 | align 16 |
5153 | IgorA | 983 | proc gl_draw_triangle_select uses eax, context:dword, p0:dword,p1:dword,p2:dword |
984 | mov eax,[p2] |
||
8063 | IgorA | 985 | push dword[eax+GLVertex.zp+offs_Z] |
5153 | IgorA | 986 | mov eax,[p1] |
8063 | IgorA | 987 | push dword[eax+GLVertex.zp+offs_Z] |
5153 | IgorA | 988 | mov eax,[p0] |
8063 | IgorA | 989 | push dword[eax+GLVertex.zp+offs_Z] |
5153 | IgorA | 990 | stdcall gl_add_select1, [context] ;,p0.zp.z, p1.zp.z, p2.zp.z |
991 | ret |
||
992 | endp |
||
993 | |||
5175 | IgorA | 994 | if PROFILE eq 1 |
995 | count_triangles dd ? |
||
996 | count_triangles_textured dd ? |
||
997 | count_pixels dd ? |
||
998 | end if |
||
5153 | IgorA | 999 | |
6134 | IgorA | 1000 | align 16 |
5175 | IgorA | 1001 | proc gl_draw_triangle_fill, context:dword, p0:dword,p1:dword,p2:dword |
1002 | pushad |
||
1003 | if PROFILE eq 1 |
||
5153 | IgorA | 1004 | ; int norm; |
1005 | ; assert(p0->zp.x >= 0 && p0->zp.x < c->zb->xsize); |
||
1006 | ; assert(p0->zp.y >= 0 && p0->zp.y < c->zb->ysize); |
||
1007 | ; assert(p1->zp.x >= 0 && p1->zp.x < c->zb->xsize); |
||
1008 | ; assert(p1->zp.y >= 0 && p1->zp.y < c->zb->ysize); |
||
1009 | ; assert(p2->zp.x >= 0 && p2->zp.x < c->zb->xsize); |
||
1010 | ; assert(p2->zp.y >= 0 && p2->zp.y < c->zb->ysize); |
||
1011 | |||
1012 | ; norm=(p1->zp.x-p0->zp.x)*(p2->zp.y-p0->zp.y)- |
||
1013 | ; (p2->zp.x-p0->zp.x)*(p1->zp.y-p0->zp.y); |
||
1014 | ; count_pixels+=abs(norm)/2; |
||
5175 | IgorA | 1015 | inc dword[count_triangles] |
1016 | end if |
||
5153 | IgorA | 1017 | |
5175 | IgorA | 1018 | mov ebx,[p1] |
8063 | IgorA | 1019 | add ebx,GLVertex.zp |
5175 | IgorA | 1020 | mov ecx,[p2] |
8063 | IgorA | 1021 | add ecx,GLVertex.zp |
5153 | IgorA | 1022 | mov edx,[context] |
6523 | IgorA | 1023 | cmp dword[edx+GLContext.texture_2d_enabled],0 |
5153 | IgorA | 1024 | je .els_i |
1025 | ;if (context.texture_2d_enabled) |
||
5175 | IgorA | 1026 | if PROFILE eq 1 |
1027 | inc dword[count_triangles_textured] |
||
1028 | end if |
||
6523 | IgorA | 1029 | mov eax,[edx+GLContext.current_texture] |
5153 | IgorA | 1030 | mov eax,[eax] ;переход по указателю |
1031 | ;так как offs_text_images+offs_imag_pixmap = 0 то context.current_texture.images[0].pixmap = [eax] |
||
6523 | IgorA | 1032 | stdcall ZB_setTexture, [edx+GLContext.zb], [eax],\ |
6243 | IgorA | 1033 | [eax+offs_imag_s_bound],[eax+offs_imag_t_bound],[eax+offs_imag_xsize_log2] |
5175 | IgorA | 1034 | mov eax,[p0] |
8063 | IgorA | 1035 | add eax,GLVertex.zp |
6134 | IgorA | 1036 | push ecx |
1037 | push ebx |
||
1038 | push eax |
||
6523 | IgorA | 1039 | push dword[edx+GLContext.zb] |
1040 | cmp dword[edx+GLContext.matrix_model_projection_no_w_transform],0 |
||
6134 | IgorA | 1041 | je @f |
1042 | call ZB_fillTriangleMappingPerspective |
||
1043 | jmp .end_f |
||
1044 | align 4 |
||
1045 | @@: |
||
1046 | call ZB_fillTriangleMapping |
||
5153 | IgorA | 1047 | jmp .end_f |
6134 | IgorA | 1048 | align 4 |
5153 | IgorA | 1049 | .els_i: |
5175 | IgorA | 1050 | mov eax,[p0] |
8063 | IgorA | 1051 | add eax,GLVertex.zp |
6523 | IgorA | 1052 | cmp dword[edx+GLContext.current_shade_model],GL_SMOOTH |
5175 | IgorA | 1053 | jne .els |
1054 | ;else if (context.current_shade_model == GL_SMOOTH) |
||
6523 | IgorA | 1055 | stdcall ZB_fillTriangleSmooth, dword[edx+GLContext.zb],eax,ebx,ecx |
5175 | IgorA | 1056 | jmp .end_f |
6134 | IgorA | 1057 | align 4 |
5175 | IgorA | 1058 | .els: |
6523 | IgorA | 1059 | stdcall ZB_fillTriangleFlat, dword[edx+GLContext.zb],eax,ebx,ecx |
5153 | IgorA | 1060 | .end_f: |
5175 | IgorA | 1061 | popad |
5153 | IgorA | 1062 | ret |
1063 | endp |
||
1064 | |||
1065 | ; Render a clipped triangle in line mode |
||
1066 | |||
6134 | IgorA | 1067 | align 16 |
5153 | IgorA | 1068 | proc gl_draw_triangle_line uses eax ebx ecx edx, context:dword, p0:dword,p1:dword,p2:dword |
1069 | mov edx,[context] |
||
6523 | IgorA | 1070 | cmp dword[edx+GLContext.depth_test],0 |
5153 | IgorA | 1071 | je .els |
1072 | lea ecx,[ZB_line_z] |
||
1073 | jmp @f |
||
6134 | IgorA | 1074 | align 4 |
5153 | IgorA | 1075 | .els: |
1076 | lea ecx,[ZB_line] |
||
1077 | @@: |
||
1078 | |||
1079 | ;if (p0.edge_flag) ZB_line_z(context.zb,&p0.zp,&p1.zp) |
||
1080 | mov eax,[p0] |
||
8063 | IgorA | 1081 | cmp dword[eax+GLVertex.edge_flag],0 |
5153 | IgorA | 1082 | je @f |
8063 | IgorA | 1083 | lea ebx,[eax+GLVertex.zp] |
5153 | IgorA | 1084 | mov eax,[p1] |
8063 | IgorA | 1085 | add eax,GLVertex.zp |
6523 | IgorA | 1086 | stdcall ecx,dword[edx+GLContext.zb],ebx,eax |
5153 | IgorA | 1087 | @@: |
1088 | ;if (p1.edge_flag) ZB_line_z(context.zb,&p1.zp,&p2.zp) |
||
1089 | mov eax,[p1] |
||
8063 | IgorA | 1090 | cmp dword[eax+GLVertex.edge_flag],0 |
5153 | IgorA | 1091 | je @f |
8063 | IgorA | 1092 | lea ebx,[eax+GLVertex.zp] |
5153 | IgorA | 1093 | mov eax,[p2] |
8063 | IgorA | 1094 | add eax,GLVertex.zp |
6523 | IgorA | 1095 | stdcall ecx,dword[edx+GLContext.zb],ebx,eax |
5153 | IgorA | 1096 | @@: |
1097 | ;if (p2.edge_flag) ZB_line_z(context.zb,&p2.zp,&p0.zp); |
||
1098 | mov eax,[p2] |
||
8063 | IgorA | 1099 | cmp dword[eax+GLVertex.edge_flag],0 |
5153 | IgorA | 1100 | je @f |
8063 | IgorA | 1101 | lea ebx,[eax+GLVertex.zp] |
5153 | IgorA | 1102 | mov eax,[p0] |
8063 | IgorA | 1103 | add eax,GLVertex.zp |
6523 | IgorA | 1104 | stdcall ecx,dword[edx+GLContext.zb],ebx,eax |
5153 | IgorA | 1105 | @@: |
1106 | |||
1107 | ret |
||
1108 | endp |
||
1109 | |||
1110 | ; Render a clipped triangle in point mode |
||
6134 | IgorA | 1111 | align 16 |
8063 | IgorA | 1112 | proc gl_draw_triangle_point uses eax edx, context:dword, p0:dword,p1:dword,p2:dword |
5153 | IgorA | 1113 | mov edx,[context] |
1114 | mov eax,[p0] |
||
8063 | IgorA | 1115 | cmp dword[eax+GLVertex.edge_flag],0 |
5153 | IgorA | 1116 | je @f |
8063 | IgorA | 1117 | lea eax,[eax+GLVertex.zp] |
1118 | stdcall ZB_plot,dword[edx+GLContext.zb],eax |
||
5153 | IgorA | 1119 | @@: |
5187 | IgorA | 1120 | mov eax,[p1] |
8063 | IgorA | 1121 | cmp dword[eax+GLVertex.edge_flag],0 |
5153 | IgorA | 1122 | je @f |
8063 | IgorA | 1123 | lea eax,[eax+GLVertex.zp] |
1124 | stdcall ZB_plot,dword[edx+GLContext.zb],eax |
||
5153 | IgorA | 1125 | @@: |
5187 | IgorA | 1126 | mov eax,[p2] |
8063 | IgorA | 1127 | cmp dword[eax+GLVertex.edge_flag],0 |
5153 | IgorA | 1128 | je @f |
8063 | IgorA | 1129 | lea eax,[eax+GLVertex.zp] |
1130 | stdcall ZB_plot,dword[edx+GLContext.zb],eax |
||
5153 | IgorA | 1131 | @@: |
1132 | ret |
||
1133 | endp>>>>>>><>><>>>*tmin)>*tmin)>0) |
||
1134 | |||
1135 | |||
1136 | |||
1137 |