Subversion Repositories Kolibri OS

Rev

Rev 5278 | Rev 5418 | 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]
5175 IgorA 711
		mov dword[norm],edi
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]
5175 IgorA 715
		mov dword[norm],edi
716
		fimul dword[norm]
717
		mov edi,dword[ecx+offs_vert_zp+offs_zbup_x]
718
		sub edi,dword[ebx+offs_vert_zp+offs_zbup_x]
719
		mov dword[norm],edi
720
		fild dword[norm]
721
		mov edi,dword[edx+offs_vert_zp+offs_zbup_y]
5208 IgorA 722
		sub edi,dword[ebx+offs_vert_zp+offs_zbup_y]
5175 IgorA 723
		mov dword[norm],edi
724
		fimul dword[norm]
5187 IgorA 725
		fsubp
5153 IgorA 726
 
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
730
		fldz
5187 IgorA 731
		fcompp
5175 IgorA 732
		fstsw ax
733
		sahf
734
		je .end_f
5353 IgorA 735
		jbe @f ;jb @f ???
5175 IgorA 736
			inc dword[front] ;front = 0.0 > norm
737
		@@:
738
		mov edi,[context]
739
		mov eax,dword[edi+offs_cont_current_front_face]
740
		xor dword[front],eax ;front ^= context.current_front_face
741
		; back face culling
742
		cmp dword[edi+offs_cont_cull_face_enabled],0
743
		je .els_1
744
			; most used case first
745
			cmp dword[edi+offs_cont_current_cull_face],GL_BACK
746
			jne @f
747
				cmp dword[front],0
748
				je .end_f
749
					stdcall dword[edi+offs_cont_draw_triangle_front], edi,ebx,ecx,edx
750
				jmp .end_f
751
			@@:
752
			cmp dword[edi+offs_cont_current_cull_face],GL_FRONT
753
			jne .end_f
754
				cmp dword[front],0
755
				jne .end_f
756
					stdcall dword[edi+offs_cont_draw_triangle_back], edi,ebx,ecx,edx
757
			jmp .end_f
758
		.els_1:
759
			; no culling
760
			cmp dword[front],0
761
			je @f
762
				stdcall dword[edi+offs_cont_draw_triangle_front], edi,ebx,ecx,edx
5213 IgorA 763
				jmp .end_f
5175 IgorA 764
			@@:
765
				stdcall dword[edi+offs_cont_draw_triangle_back], edi,ebx,ecx,edx
766
		jmp .end_f
767
	.els_0:
5208 IgorA 768
		;eax = cc[2]
5175 IgorA 769
		and eax,[cc]
5208 IgorA 770
		and eax,[cc+4] ;eax = c_and = cc[0] & cc[1] & cc[2]
5353 IgorA 771
		or eax,eax ;if (c_and==0)
772
		jnz .end_f
5175 IgorA 773
			stdcall gl_draw_triangle_clip, [context],ebx,ecx,edx,0
774
	.end_f:
775
popad
776
	ret
777
endp
5153 IgorA 778
 
5175 IgorA 779
align 4
780
proc gl_draw_triangle_clip, context:dword, p0:dword, p1:dword, p2:dword, clip_bit:dword
781
locals
782
	co dd ?
783
	cc rd 3
784
	edge_flag_tmp dd ?
785
	clip_mask dd ?
5208 IgorA 786
	q rd 3 ;GLVertex*
5175 IgorA 787
	tmp1 GLVertex ?
788
	tmp2 GLVertex ?
789
endl
790
pushad
791
	mov ebx,[p0]
792
	mov ecx,[p1]
793
	mov edx,[p2]
5208 IgorA 794
 
5175 IgorA 795
	mov edi,[ebx+offs_vert_clip_code]
5208 IgorA 796
	mov [cc],edi
5175 IgorA 797
	mov eax,[ecx+offs_vert_clip_code]
5208 IgorA 798
	mov [cc+4],eax
5175 IgorA 799
	or edi,eax
800
	mov eax,[edx+offs_vert_clip_code]
5208 IgorA 801
	mov [cc+8],eax
5175 IgorA 802
	or edi,eax
5208 IgorA 803
	mov [co],edi ;co = cc[0] | cc[1] | cc[2]
5175 IgorA 804
 
5353 IgorA 805
	or edi,edi ;if (co == 0)
806
	jnz .els_0
5175 IgorA 807
		stdcall gl_draw_triangle, [context],ebx,ecx,edx
808
		jmp .end_f
809
	.els_0:
5208 IgorA 810
		;eax = cc[2]
5175 IgorA 811
		and eax,[cc]
5208 IgorA 812
		and eax,[cc+4] ;c_and = cc[0] & cc[1] & cc[2]
5175 IgorA 813
 
814
		; the triangle is completely outside
5353 IgorA 815
		or eax,eax ;if (c_and!=0) return
816
		jnz .end_f
5175 IgorA 817
 
5208 IgorA 818
		; find the next direction to clip
819
		.cycle_0: ;while (clip_bit < 6 && (co & (1 << clip_bit)) == 0)
820
		cmp dword[clip_bit],6
821
		jge .cycle_0_end
822
		xor eax,eax
823
		inc eax
824
		mov ecx,[clip_bit]
825
		shl eax,cl
826
		and eax,[co]
5353 IgorA 827
		or eax,eax
828
		jnz .cycle_0_end
5208 IgorA 829
			inc dword[clip_bit]
830
			jmp .cycle_0
831
		.cycle_0_end:
5153 IgorA 832
 
5175 IgorA 833
	; this test can be true only in case of rounding errors
834
	cmp dword[clip_bit],6
835
if 0
836
	jne @f
5153 IgorA 837
;      printf("Error:\n");
838
;      printf("%f %f %f %f\n",p0->pc.X,p0->pc.Y,p0->pc.Z,p0->pc.W);
839
;      printf("%f %f %f %f\n",p1->pc.X,p1->pc.Y,p1->pc.Z,p1->pc.W);
840
;      printf("%f %f %f %f\n",p2->pc.X,p2->pc.Y,p2->pc.Z,p2->pc.W);
5175 IgorA 841
		jmp .end_f
842
	@@:
5208 IgorA 843
end if
844
if 1
5175 IgorA 845
	je .end_f
846
end if
5153 IgorA 847
 
5208 IgorA 848
	xor eax,eax
849
	inc eax
850
	mov ecx,[clip_bit]
851
	shl eax,cl
852
	mov [clip_mask],eax ;1 << clip_bit
853
	mov edi,[cc]
854
	xor edi,[cc+4]
855
	xor edi,[cc+8]
856
	and eax,edi ;eax = co1 = (cc[0] ^ cc[1] ^ cc[2]) & clip_mask
5153 IgorA 857
 
5208 IgorA 858
	mov ecx,[p1] ;востанавливаем после shl ___,cl
5153 IgorA 859
 
5353 IgorA 860
	or eax,eax ;if (co1)
861
	jz .els_1
5208 IgorA 862
		; one point outside
863
		mov eax,[cc]
864
		and eax,[clip_mask]
5353 IgorA 865
		or eax,eax ;if (cc[0] & clip_mask)
866
		jz .els_2
5208 IgorA 867
			;q[0]=p0 q[1]=p1 q[2]=p2
868
			mov [q],ebx
869
			mov [q+4],ecx
870
			mov [q+8],edx
871
			jmp .els_2_end
872
		.els_2:
873
		mov eax,[cc+4]
874
		and eax,[clip_mask]
5353 IgorA 875
		or eax,eax ;else if (cc[1] & clip_mask)
876
		jz .els_3
5208 IgorA 877
			;q[0]=p1 q[1]=p2 q[2]=p0
878
			mov [q],ecx
879
			mov [q+4],edx
880
			mov [q+8],ebx
881
			jmp .els_2_end
882
		.els_3:
883
			;q[0]=p2 q[1]=p0 q[2]=p1
884
			mov [q],edx
885
			mov [q+4],ebx
886
			mov [q+8],ecx
887
		.els_2_end:
5153 IgorA 888
 
5208 IgorA 889
		mov ebx,[q]
890
		add ebx,offs_vert_pc
891
		mov ecx,[q+4]
892
		add ecx,offs_vert_pc
893
		mov edx,[q+8]
894
		add edx,offs_vert_pc
5153 IgorA 895
 
5208 IgorA 896
		lea eax,[clip_proc]
897
		mov edi,[clip_bit]
898
		shl edi,2
899
		add eax,edi
900
		mov edi,ebp
901
		sub edi,(2*sizeof.GLVertex)-offs_vert_pc
902
		stdcall dword[eax],edi,ebx,ecx ;clip_proc[clip_bit](&tmp1.pc,&q[0].pc,&q[1].pc)
903
		sub edi,offs_vert_pc
5153 IgorA 904
 
5208 IgorA 905
		sub ebx,offs_vert_pc
906
		sub ecx,offs_vert_pc
907
		stdcall updateTmp,[context],edi,ebx,ecx,eax ;updateTmp(c,&tmp1,q[0],q[1],tt)
908
		add ebx,offs_vert_pc
5153 IgorA 909
 
5208 IgorA 910
		lea eax,[clip_proc]
911
		mov edi,[clip_bit]
912
		shl edi,2
913
		add eax,edi
914
		mov edi,ebp
915
		sub edi,sizeof.GLVertex-offs_vert_pc
916
		stdcall dword[eax],edi,ebx,edx ;clip_proc[clip_bit](&tmp2.pc,&q[0].pc,&q[2].pc)
917
		sub edi,offs_vert_pc
918
		sub ebx,offs_vert_pc
919
		sub edx,offs_vert_pc
920
		stdcall updateTmp,[context],edi,ebx,edx,eax ;updateTmp(c,&tmp2,q[0],q[2],tt)
921
 
922
		mov eax,[ebx+offs_vert_edge_flag]
5353 IgorA 923
		mov [tmp1.edge_flag],eax ;q[0].edge_flag
5208 IgorA 924
		mov eax,[edx+offs_vert_edge_flag]
925
		mov [edge_flag_tmp],eax	;q[2].edge_flag
926
		mov dword[edx+offs_vert_edge_flag],0 ;q[2].edge_flag=0
927
		mov eax,[clip_bit]
928
		inc eax
929
		push eax ;для вызова нижней функции
930
		mov edi,ebp
931
		sub edi,2*sizeof.GLVertex
932
		stdcall gl_draw_triangle_clip,[context],edi,ecx,edx,eax ;gl_draw_triangle_clip(c,&tmp1,q[1],q[2],clip_bit+1)
933
 
934
		mov dword[tmp2.edge_flag],0
935
		mov dword[tmp1.edge_flag],0
936
		mov eax,[edge_flag_tmp]
937
		mov [edx+offs_vert_edge_flag],eax ;q[2].edge_flag=edge_flag_tmp
938
		push edx
939
		push edi
940
		add edi,sizeof.GLVertex ;edi = &tmp2
941
		stdcall gl_draw_triangle_clip,[context],edi ;gl_draw_triangle_clip(c,&tmp2,&tmp1,q[2],clip_bit+1)
942
		jmp .end_f
943
	.els_1:
944
		; two points outside
945
		mov eax,[cc]
946
		and eax,[clip_mask]
947
		cmp eax,0 ;if (cc[0] & clip_mask)==0
948
		jne .els_4
949
			;q[0]=p0 q[1]=p1 q[2]=p2
950
			mov [q],ebx
951
			mov [q+4],ecx
952
			mov [q+8],edx
953
			jmp .els_4_end
954
		.els_4:
955
		mov eax,[cc+4]
956
		and eax,[clip_mask]
957
		cmp eax,0 ;else if (cc[1] & clip_mask)==0
958
		jne .els_5
959
			;q[0]=p1 q[1]=p2 q[2]=p0
960
			mov [q],ecx
961
			mov [q+4],edx
962
			mov [q+8],ebx
963
			jmp .els_4_end
964
		.els_5:
965
			;q[0]=p2 q[1]=p0 q[2]=p1
966
			mov [q],edx
967
			mov [q+4],ebx
968
			mov [q+8],ecx
969
		.els_4_end:
970
 
971
		mov ebx,[q]
972
		add ebx,offs_vert_pc
973
		mov ecx,[q+4]
974
		add ecx,offs_vert_pc
975
		mov edx,[q+8]
976
		add edx,offs_vert_pc
977
 
978
		lea eax,[clip_proc]
979
		mov edi,[clip_bit]
980
		shl edi,2
981
		add eax,edi
982
		mov edi,ebp
983
		sub edi,(2*sizeof.GLVertex)-offs_vert_pc
984
		stdcall dword[eax],edi,ebx,ecx ;clip_proc[clip_bit](&tmp1.pc,&q[0].pc,&q[1].pc)
985
		sub edi,offs_vert_pc
986
		stdcall updateTmp,[context],edi,[q],[q+4],eax
987
 
988
		lea eax,[clip_proc]
989
		mov edi,[clip_bit]
990
		shl edi,2
991
		add eax,edi
992
		mov edi,ebp
993
		sub edi,sizeof.GLVertex-offs_vert_pc
994
		stdcall dword[eax],edi,ebx,edx ;clip_proc[clip_bit](&tmp2.pc,&q[0].pc,&q[2].pc)
995
		sub edi,offs_vert_pc
996
		stdcall updateTmp,[context],edi,[q],[q+8],eax
997
 
5353 IgorA 998
		mov dword[tmp1.edge_flag],1
999
		mov eax,[edx+offs_vert_edge_flag-offs_vert_pc]
1000
		mov dword[tmp2.edge_flag],eax ;tmp2.edge_flag = q[2].edge_flag
5208 IgorA 1001
		mov eax,[clip_bit]
1002
		inc eax
1003
		push eax
1004
		push edi
1005
		sub edi,sizeof.GLVertex
1006
		stdcall gl_draw_triangle_clip,[context],[q],edi ;gl_draw_triangle_clip(c,q[0],&tmp1,&tmp2,clip_bit+1)
5175 IgorA 1007
	.end_f:
1008
popad
1009
	ret
1010
endp
5153 IgorA 1011
 
1012
align 4
1013
proc gl_draw_triangle_select uses eax, context:dword, p0:dword,p1:dword,p2:dword
1014
	mov eax,[p2]
1015
	push dword[eax+offs_vert_zp+offs_Z]
1016
	mov eax,[p1]
1017
	push dword[eax+offs_vert_zp+offs_Z]
1018
	mov eax,[p0]
1019
	push dword[eax+offs_vert_zp+offs_Z]
1020
	stdcall gl_add_select1, [context] ;,p0.zp.z, p1.zp.z, p2.zp.z
1021
	ret
1022
endp
1023
 
5175 IgorA 1024
if PROFILE eq 1
1025
	count_triangles dd ?
1026
	count_triangles_textured dd ?
1027
	count_pixels dd ?
1028
end if
5153 IgorA 1029
 
1030
align 4
5175 IgorA 1031
proc gl_draw_triangle_fill, context:dword, p0:dword,p1:dword,p2:dword
1032
pushad
1033
if PROFILE eq 1
5153 IgorA 1034
;    int norm;
1035
;    assert(p0->zp.x >= 0 && p0->zp.x < c->zb->xsize);
1036
;    assert(p0->zp.y >= 0 && p0->zp.y < c->zb->ysize);
1037
;    assert(p1->zp.x >= 0 && p1->zp.x < c->zb->xsize);
1038
;    assert(p1->zp.y >= 0 && p1->zp.y < c->zb->ysize);
1039
;    assert(p2->zp.x >= 0 && p2->zp.x < c->zb->xsize);
1040
;    assert(p2->zp.y >= 0 && p2->zp.y < c->zb->ysize);
1041
 
1042
;    norm=(p1->zp.x-p0->zp.x)*(p2->zp.y-p0->zp.y)-
1043
;      (p2->zp.x-p0->zp.x)*(p1->zp.y-p0->zp.y);
1044
;    count_pixels+=abs(norm)/2;
5175 IgorA 1045
	inc dword[count_triangles]
1046
end if
5153 IgorA 1047
 
5175 IgorA 1048
	mov ebx,[p1]
1049
	add ebx,offs_vert_zp
1050
	mov ecx,[p2]
1051
	add ecx,offs_vert_zp
5153 IgorA 1052
	mov edx,[context]
1053
	cmp dword[edx+offs_cont_texture_2d_enabled],0
1054
	je .els_i
1055
		;if (context.texture_2d_enabled)
5175 IgorA 1056
if PROFILE eq 1
1057
	inc dword[count_triangles_textured]
1058
end if
5153 IgorA 1059
		mov eax,dword[edx+offs_cont_current_texture]
1060
		mov eax,[eax] ;переход по указателю
1061
		;так как offs_text_images+offs_imag_pixmap = 0 то context.current_texture.images[0].pixmap = [eax]
1062
		stdcall ZB_setTexture, dword[edx+offs_cont_zb],dword[eax]
5175 IgorA 1063
		mov eax,[p0]
1064
		add eax,offs_vert_zp
1065
		stdcall ZB_fillTriangleMappingPerspective, dword[edx+offs_cont_zb],eax,ebx,ecx
5153 IgorA 1066
		jmp .end_f
1067
	.els_i:
5175 IgorA 1068
		mov eax,[p0]
1069
		add eax,offs_vert_zp
1070
		cmp dword[edx+offs_cont_current_shade_model],GL_SMOOTH
1071
		jne .els
1072
			;else if (context.current_shade_model == GL_SMOOTH)
1073
			stdcall ZB_fillTriangleSmooth, dword[edx+offs_cont_zb],eax,ebx,ecx
1074
			jmp .end_f
1075
		.els:
1076
			stdcall ZB_fillTriangleFlat, dword[edx+offs_cont_zb],eax,ebx,ecx
5153 IgorA 1077
	.end_f:
5175 IgorA 1078
popad
5153 IgorA 1079
	ret
1080
endp
1081
 
1082
; Render a clipped triangle in line mode
1083
 
1084
align 4
1085
proc gl_draw_triangle_line uses eax ebx ecx edx, context:dword, p0:dword,p1:dword,p2:dword
1086
	mov edx,[context]
1087
	cmp dword[edx+offs_cont_depth_test],0
1088
	je .els
1089
		lea ecx,[ZB_line_z]
1090
		jmp @f
1091
	.els:
1092
		lea ecx,[ZB_line]
1093
	@@:
1094
 
1095
	;if (p0.edge_flag) ZB_line_z(context.zb,&p0.zp,&p1.zp)
1096
	mov eax,[p0]
1097
	cmp dword[eax+offs_vert_edge_flag],0
1098
	je @f
1099
		mov ebx,eax
1100
		add ebx,offs_vert_zp
1101
		mov eax,[p1]
1102
		add eax,offs_vert_zp
1103
		stdcall ecx,dword[edx+offs_cont_zb],ebx,eax
1104
	@@:
1105
	;if (p1.edge_flag) ZB_line_z(context.zb,&p1.zp,&p2.zp)
1106
	mov eax,[p1]
1107
	cmp dword[eax+offs_vert_edge_flag],0
1108
	je @f
1109
		mov ebx,eax
1110
		add ebx,offs_vert_zp
1111
		mov eax,[p2]
1112
		add eax,offs_vert_zp
1113
		stdcall ecx,dword[edx+offs_cont_zb],ebx,eax
1114
	@@:
1115
	;if (p2.edge_flag) ZB_line_z(context.zb,&p2.zp,&p0.zp);
1116
	mov eax,[p2]
1117
	cmp dword[eax+offs_vert_edge_flag],0
1118
	je @f
1119
		mov ebx,eax
1120
		add ebx,offs_vert_zp
1121
		mov eax,[p0]
1122
		add eax,offs_vert_zp
1123
		stdcall ecx,dword[edx+offs_cont_zb],ebx,eax
1124
	@@:
1125
 
1126
	ret
1127
endp
1128
 
1129
; Render a clipped triangle in point mode
1130
align 4
1131
proc gl_draw_triangle_point uses eax ebx edx, context:dword, p0:dword,p1:dword,p2:dword
1132
	mov edx,[context]
1133
	mov eax,[p0]
1134
	cmp dword[eax+offs_vert_edge_flag],0
1135
	je @f
1136
		mov ebx,eax
1137
		add ebx,offs_vert_zp
1138
		stdcall ZB_plot,dword[edx+offs_cont_zb],ebx
1139
	@@:
5187 IgorA 1140
	mov eax,[p1]
5153 IgorA 1141
	cmp dword[eax+offs_vert_edge_flag],0
1142
	je @f
1143
		mov ebx,eax
1144
		add ebx,offs_vert_zp
1145
		stdcall ZB_plot,dword[edx+offs_cont_zb],ebx
1146
	@@:
5187 IgorA 1147
	mov eax,[p2]
5153 IgorA 1148
	cmp dword[eax+offs_vert_edge_flag],0
1149
	je @f
1150
		mov ebx,eax
1151
		add ebx,offs_vert_zp
1152
		stdcall ZB_plot,dword[edx+offs_cont_zb],ebx
1153
	@@:
1154
	ret
1155
endp
1156
 
1157
 
1158
 
1159