Subversion Repositories Kolibri OS

Rev

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