Subversion Repositories Kolibri OS

Rev

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