Subversion Repositories Kolibri OS

Rev

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